Forum Moderators: phranque
I am trying to redirect URLs consisting of advanced strings (produced by CMS nukeCGP) from my old website to the new, nice URLs. I have also switched CMS systems in between.
Google and other search engines still have the old ones indexed, and I do not want to lose the ranking and search results, so I'd like to redirect them to the new ones.
Old URL: http://www.example.com/index.php?name=News&file=article&sid=1
New URL: http://www.example.com/about/
Using search functions, I have managed to find something that worked - as described here: [webmasterworld.com...]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} &?name=News&file=article&sid=1&?
RewriteRule ^index\.php$ http://www.example.com/about/? [R=301,L] The catch is, that for http://www.example.com/index.php?name=News&file=article&sid=11 (and sid=12, 13, 14, 15, 16, 17, 18, 19, 100, 101, 102, etc.) all redirect to the first instance (sid=1), and not to the right one (with their own id).
Could someone please advise how to modify the above code to only redirect the correct (individual) URL?
[edited by: jdMorgan at 6:41 pm (utc) on Aug. 10, 2008]
[edit reason] example.com [/edit]
The code actually looks correct, in that the rewritecond pattern says that if any character follows "sid=1" then it has to be an ampersand. Did you completely flush your browser cache before testing?
You could also try the pattern "^name=News&file=article&sid=1$" which will require an exact match.
Jim
[edited by: jdMorgan at 6:46 pm (utc) on Aug. 10, 2008]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} &?name=News&file=article&sid=([0-9]*)&?
RewriteRule ^index\.php$ http://www.example.com/about/?name=News&file=article&sid=%1 [R=301,L]
I can't give an exact answer because I don't know your exact URL formats (for both sites).
thanks for taking the time to look into my request.
I am not very experienced in coding, so I really feel stupid because the solution was quite simple - take out the '&?' string at the end, and replace it by '$' - what jdMorgan suggested.
My code is therefore
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} &?name=News&file=article&sid=1$
RewriteRule ^index\.php$ http://www.example.com/about/? [R=301,L] The problem with g1smd solution is that I do not have a consistent system for redirects (sid=2 redirects to /links/, sid=3 to /history/, etc.), so I have to manually redirect each link. Fortunately, there are not that many :)
Thanks again; especially to jdMorgan for providing the solution which works for me!