我有以下规则。WordPress上的htaccess文件(单次安装):
# REWRITE FORUMS DOMAIN TO FOLDER
RewriteCond %{HTTP_HOST} ^forums\\.example\\.com$
RewriteRule !^forums/? forums%{REQUEST_URI} [NC,L]
# REWRITE FORUMS FOLDER TO SUBDOMAIN
RewriteCond %{THE_REQUEST} \\s/forums/([^\\s]*) [NC]
RewriteRule ^ http://forums.example.com/%1 [R=301,L]
这是因为
http://example.com/forums
访问地址
http://forums.example.com/
然而,服务器突然出现500服务器错误。。。
有什么办法吗?These rules work perfectly when used on non-wordpress sites... 第二条重写规则成功地将/论坛发送到子域,但子域似乎无法将数据正确地传递到WordPress中。”
整个htaccess文件如下所示:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# REWRITE FORUMS DOMAIN TO FOLDER
RewriteCond %{HTTP_HOST} ^forums\\.example\\.com$
RewriteRule !^forums/? forums%{REQUEST_URI} [NC,L]
# REWRITE FORUMS FOLDER TO SUBDOMAIN
RewriteCond %{THE_REQUEST} \\s/forums/([^\\s]*) [NC]
RewriteRule ^ http://forums.example.com/%1 [R=301,L]
# BEGIN WordPress
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>
The reason that the WordPress rules are after the forums rules are because if I put them after then they are never hit!
SO网友:tutankhamun
我提供以下解决方案。需要在这行前面加上索引。php。
if (!empty($_SERVER[\'REDIRECT_URL\'])) {
$_SERVER[\'REQUEST_URI\'] = $_SERVER[\'REDIRECT_URL\'];
}
我知道这是一个肮脏的黑客,但WordPress重写机制基于
$_SERVER[\'REQUEST_URI\']
价值
这些规则仅在以下链接上测试(与另一个域)http://example.com/forums/ 和http://forums.example.com/如果在其他链接上不起作用,请告诉我。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# WordPress native stop rule
RewriteRule ^index\\.php$ - [L]
# prepend subdomain prefix
RewriteCond %{REQUEST_URI} !^/index\\.php$
RewriteCond %{HTTP_HOST} ^forums\\.example\\.coml$
RewriteRule !^forums/? forums%{REQUEST_URI} [NC,L]
# redirect to subdomain
RewriteCond %{HTTP_HOST} !^forums\\.example\\.com$
RewriteCond %{REQUEST_URI} ^/forums/(.*) [NC]
RewriteRule ^ http://forums.example.com/%1 [R=301,L]
# WordPress native rewrite with avoiding existing file- and dir- links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# avoid rewrite endless loop (to be on the safe side)
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
</IfModule>