Forum Moderators: phranque

Message Too Old, No Replies

Help with Permanent Redirect

htaccess 301 custom redirects

         

johny_rmx

5:36 pm on Aug 10, 2008 (gmt 0)

10+ Year Member



Hi,

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]

jdMorgan

6:45 pm on Aug 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The simple answer is, put the Rules for 11, 12, 13, etc. before this one. But I'm not sure if that's what you meant.

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]

g1smd

7:47 pm on Aug 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Something like this?

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).

johny_rmx

10:25 pm on Aug 10, 2008 (gmt 0)

10+ Year Member



Dear jdMorgan and g1smd,

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!

g1smd

6:53 pm on Aug 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Go with that. I didn't read the question as closely as I thought I had.