如何修复Cakephp中的Wordpress重定向问题? [英] How to fix Wordpress redirect issue within Cakephp?

查看:92
本文介绍了如何修复Cakephp中的Wordpress重定向问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行我的网站的CakePHP较旧实例。

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

WordPress安装在 example.com/blog 上,并且在我尝试解决另一个问题之前一直可以正常工作主页 example.com 将重定向到 example.com // 并带有双斜杠。问题在于它现在重定向到 example.com/webroot/blog

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.

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

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!

推荐答案

我尝试使用.htaccess文件无法完成所需的工作。

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

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

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

这篇关于如何修复Cakephp中的Wordpress重定向问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆