【问题标题】:How to fix Wordpress redirect issue within Cakephp?如何修复 Cakephp 中的 Wordpress 重定向问题?
【发布时间】:2018-01-20 00:43:34
【问题描述】:

我安装了一个较旧的 CakePHP 实例来运行我的网站。

WordPress 安装在 example.com/blog 上,并且在我尝试修复另一个问题之前,WordPress 安装在 example.com 上,主页 example.com 将重定向到带有双斜杠的 example.com//。问题是它现在重定向到example.com/webroot/blog。

这是我的 htaccess 文件和目录结构:

/var/www/.htaccess

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ html/webroot/    [L]
   RewriteRule    (.*) html/webroot/$1 [L]
</IfModule>

/var/www/html/.htaccess

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
   RewriteRule ^.*$ http://www.example.com%{REQUEST_URI} [R=301,L]   
   RewriteRule ^(.*)/$ /$1 [L,R=301]
   RewriteRule    ^$    webroot/    [L]
   RewriteRule    (.*) webroot/$1    [L]
</IfModule>

/var/www/html/webroot/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
#   RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
#   RewriteRule ^(.*)$ $1/ [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

/var/www/html/webroot/blog/.htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress

任何帮助将不胜感激。谢谢!

【问题讨论】:

  • /var/www/html/webroot/ 是您的 example.com 域的 Web 根文件夹吗?如果是这样,您不需要在/var/www/ 和/var/www/html/ 中使用htaccess。然后,在/var/www/html/webroot/.htaccess 中,由于对两行有罪的行进行了注释,因此请尝试清除浏览器的缓存并重试。我还要在/var/www/html/webroot/.htaccess 中添加一个条件,以保持/blog/ 请求保持不变
  • 感谢@JustinIurman 的回复。 /var/www/html 是我使用 cakephp 的主要网站根目录。 /var/www/html/webroot/blog 是博客。我该怎么办?
  • 这很奇怪。您是否完全确定您没有看到缓存的重定向(开发工具+在请求时禁用缓存,使用 curl)?您是否尝试过逐个文件禁用 .htaccess 文件以查看哪个负责该重定向?
  • @JustinIurman 我如何让这些请求保持原样?
  • 如果 /var/www/html 是你的文档根目录并且有你的 cakephp 应用程序,为什么你有 webroot 文件夹/为什么博客不直接在 /var/www/html/blog 中?另外,预期的结果是什么? example.com 加载 /var/www/html/index.php,/blog/ 下面的任何内容都转到 /var/www/html/webroot/blog/index.php(又名默认 WP)?

标签: php wordpress apache .htaccess cakephp


【解决方案1】:

正如我所尝试的,无法使用 .htaccess 文件完成您需要的操作。

您必须在 Apache 中创建一个别名。

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/

        <Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
                Require all granted
        </Directory>

Alias "/blog" "/var/www/html/webroot/blog"

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
LogLevel alert rewrite:trace3 alias:debug


        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>


# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    • 2022-01-16
    • 1970-01-01
    相关资源
    最近更新 更多