保存设置时网站重定向到错误的URL

时间:2016-09-20 作者:Muhammad Riyaz

我有一个子域:

https://blog.example.com/
我强制重定向到子目录:

https://www.example.com/blog
通过更改网站URL和一些RewriteRule 在…上.htaccess.

现在,网站和管理员工作正常,除了一个小问题,例如当我试图单击设置页面上的保存按钮时(例如:设置>写入),网站重定向到主域:

https://www.example.com/wp-admin/options-writing.php?settings-updated=true
/blog 在URL中丢失,并最终进入主网站404页。

我的htaccess文件如下所示:

    # BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Host}i ^example\\.com
RewriteCond %{HTTP_HOST} ^blog\\.example\\.com$
RewriteRule ^/?(.*)$ https://www.example.com/blog/$1 [L,R=301,NC]

RewriteCond %{HTTP:X-Forwarded-Server}i !^www\\.example\\.com
RewriteCond %{HTTP_HOST} ^blog\\.example\\.com$
RewriteRule ^/?[0-9]{4}/[0-9]{2}/(.*)$ https://www.example.com/blog/$1 [L,R=301,NC]

RewriteCond %{HTTP:X-Forwarded-Server}i !^www\\.example\\.com
RewriteCond %{HTTP_HOST} ^blog\\.example\\.com$
RewriteRule ^/?(.*)$ https://www.example.com/blog/$1 [L,R=301,NC]

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*)$ https://www.example.com/blog/$1 [L,R=301,NC]


RewriteBase /
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# 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
单击“保存”按钮时,控制台会显示一条错误消息:

/wp-admin/options-general.php?settings-updated=true:1 GET https://www.example.com/wp-admin/options-general.php?settings-updated=true 404 ()
有人能帮我弄清楚吗?

已更新工作。htaccess(根据第一个答案):

<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]

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^/?(.*)$ https://www.example.com/blog/$1 [L,R=301,NC]
</IfModule>
我的wordpress地址和网站地址是:

WordPress Address (URL) =   /blog
Site Address (URL) = https://www.example.com/blog

1 个回复
SO网友:Ethan O\'Sullivan

从看你的.htaccess, 看起来您的规则重叠太多了。请执行以下操作:

备份您当前的.htaccess 如果需要返回,请删除.htaccess 从服务器上,WordPress会自动为您创建一个新的.htaccess 文件,并在<IfModule mod_rewrite.c> 标签:。

RewriteCond %{HTTP_HOST} ^blog\\.example\\.com$
RewriteRule ^/?(.*)$ https://www.example.com/blog/$1 [L,R=301,NC]
您的.htaccess 然后应如下所示:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# Custom rewrite
RewriteCond %{HTTP_HOST} ^blog\\.example\\.com$
RewriteRule ^/?(.*)$ https://www.example.com/blog/$1 [L,R=301,NC]
</IfModule>
# END WordPress

相关推荐

.htaccess中的WordPress类别页重定向不起作用

Wordpress自动生成类别页面,例如:https://planthardware.com/category/microgreens/recommended-equipment/我想将其重定向到自定义页面,例如:https://planthardware.com/microgreens-equipment/最简单的方法是什么?我试过这个(我怀疑这太复杂了):RewriteEngine on RewriteBase / RewriteRule ^category/microgreens/r