Reputation: 35
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.
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. How do I do this?
Upvotes: 1
Views: 60
Reputation: 24458
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>
Upvotes: 1