简体   繁体   English

.htaccess mod_rewrite在Wordpress中的顺序

[英].htaccess mod_rewrite order in Wordpress

I'm trying to redirect my old webpage traffic to another while keeping some links working and pointing to same content on the new site using .htaccess RewriteRule in Wordpress. 我正在尝试将旧网页流量重定向到另一个网页,同时保持某些链接正常运行,并使用Wordpress中的.htaccess RewriteRule指向新站点上的相同内容。

I use pretty permalinks and while these are redirecting fine as soon as I try to redirect rest of the content they doesn't resolve. 我使用漂亮的永久链接,而当我尝试重定向其余无法解决的内容时,它们的重定向很好。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^blog$ http://newsite.com/news/ [R=301,L]
RewriteRule ^news/(.*)$ http://newsite.com/news/$1/ [R=301,L]
RewriteRule ^old-category/(.*)$ http://newsite.com/news/$1/ [R=301,L]
</IfModule>

The above works fine and produce proper redirects even if someone uses link like 上面的方法工作正常,即使有人使用类似

http://www.myoldsite/?p=1045       

As soon as I add something like 一旦我添加类似

RewriteRule ^(.*)$ http://www.newsite.com [R=301,L]

It produces links like this 它产生这样的链接

htttp://mynewsite/?p=1045

I can't wrap my head around the order that these rules are processed. 我无法确定这些规则的处理顺序。 I want to let the pretty permalink generate and then if it doesn't follow the any of the above rules go to the home page under newsite.com. 我想让漂亮的永久链接生成,然后如果不遵循上述任何规则,请转到newsite.com下的主页。 How do I do this? 我该怎么做呢?

Try this 尝试这个

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} p=1045$
RewriteRule ^(.*) http://newsite.com/tutorials? [R=301,L] 
RewriteRule ^blog$ http://newsite.com/news/ [R=301,L]
RewriteRule ^news/(.*)$ http://newsite.com/news/$1/ [R=301,L]
RewriteRule ^old-category/(.*)$ http://newsite.com/news/$1/ [R=301,L]
RewriteRule ^(.*)$ http://www.newsite.com/? [R=301,L]
</IfModule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM