我使用WordPress永久链接和带参数的自定义重定向。不幸的是,自定义重定向无效。
我的代码:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^old_folder/page\.htm$ /new_folder/page/? [L,R=301]
RewriteCond %{QUERY_STRING} (^|&)lang=de($|&)
RewriteRule ^old_folder/page\.htm$ /new_folder/page/? [L,R=301]
...
</IfModule>
代码有问题吗?
答案 0 :(得分:3)
你应该在Wordpress Dispatcher之前进行重定向:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^old_folder/page\.htm$ /new_folder/page/? [L,R=301]
RewriteCond %{QUERY_STRING} (^|&)lang=de($|&)
RewriteRule ^old_folder/page\.htm$ /new_folder/page/? [L,R=301]
...
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
与@vitozev一样,否则调度员将首先捕获请求并因[L]
标志而停止处理其他规则。
您应该避免在# BEGIN
和# END
评论之间修改规则。