Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
Try this at the top of your .htaccess
file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule old-url-here/ http://www.new-server.com/new-structure [R=301,L]
</IfModule>
Please make sure you have a backup copy of that .htaccess
file first.
Edit: Query string, I always forget the query string…
It get’s real ugly with the query string.
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} ^p=1$
RewriteRule (.*) http://www.new-server.com/new-post-url [R=301,L]
</IfModule>
That didn’t work I’m afraid, I’m sure it’s the ? that’s causing the issue as it the normal 301 work correctly without it…
Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
Is mod_rewrite enabled for that directory on your server and directory?
Easy way to check, just add these lines to the very top.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule send-me-to-cnn/ http://www.cnn.com/ [R=301,L]
</IfModule>
And visit http://your-url-here/send-me-to-cnn/
with your web browser.
Let me know if you get 301’ed to CNN’s web site. I just tried it on one of my sites and that worked.
Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
I’m sure it’s the ? that’s causing the issue as it the normal 301 work correctly without it…
It’s the query string. That’s why I modified my original post.
That worked correctly for the send-me-to-cnn rule and the RewriteEngine on code was already implemented when I first set the site up.
Then I tried your edited post and it works perfectly 🙂
Do you know if I could implement the code with a HTTP_HOST condition so that only traffic from a specified domain works with the redirects? I only ask as it’s a multisite installation and if another domain gets pointed to the server it might conflict if they have existing similar permalinks.
RewriteCond %{HTTP_HOST} ^www.xxx.com$
Thank you ever so much for your help too, much appreciated!
Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
It’s untested but I think this may work.
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^www\.xxx\.com$
RewriteCond %{QUERY_STRING} ^p=1$
RewriteRule (.*) http://www.new-server.com/new-post-url [R=301,L]
</IfModule>
Give that a try.
That seems like it’s working on my test server, will try it out on the live one later on.
Thank you again so much for your help 🙂
Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
You’re welcome, glad to help. 😉