如何解决Cakephp中的Wordpress重定向问题?

时间:2018-01-15 14:44:09

标签: php wordpress apache .htaccess cakephp

我安装了运行我网站的旧版CakePHP实例。

WordPress已安装在example.com/blog上,并且在我尝试修复主页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

非常感谢任何帮助。谢谢!

1 个答案:

答案 0 :(得分: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