How to fix Wordpress redirect issue within Cakephp?

余生颓废 提交于 2020-01-03 03:49:05

问题


I have an older instance of CakePHP installed running my website.

WordPress is installed on example.com/blog and used to work fine until I tried to fix another issue where the homepage example.com would redirect to example.com// with double slashes. The issue is that it now redirects to example.com/webroot/blog.

Here are my htaccess files and directory structure:

/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

Any help would be greatly appreciated. Thanks!


回答1:


As I tried it is not possible to do what you need with .htaccess files.

You must create an alias in 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


来源:https://stackoverflow.com/questions/48265228/how-to-fix-wordpress-redirect-issue-within-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!