Forum Moderators: phranque

Message Too Old, No Replies

301 redirects from dynamic to SEO style URL

         

nicolew

11:30 pm on Jan 20, 2010 (gmt 0)

10+ Year Member



Hi guys,

I know this has been covered a billion times and after many, many hours and a friend helping, I'm hoping someone here can help me!

I have an archaic CMS on a shared server with these urls:

http://www.old-example.com/categoryname?cid=1259&pid=337

And I am trying to do 301 redirects on all of these to a new Drupal site (and domain name), on a new server that has:

http://www.new-example.com/category/pagename

The rule that makes the most sense to me was:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^categoryname?cid=1259&pid=337$
RewriteRule ^melbourne$ http://www.new-example.com/category/pagename? [R=301,L]

But alas, it is not to be. I can redirect the entire site successfully so I know the .htaccess is working but I am really struggling here.

Any help would be much appreicated.

Cheers,
Nicole

[edited by: jdMorgan at 2:11 am (utc) on Jan. 21, 2010]
[edit reason] example.com [/edit]

jdMorgan

2:12 am on Jan 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks like you've got part of the URL-path in the query-string pattern, and the "melbourne" in the RewriteRule pattern appears to be spurious. Based on the URLs you specified, the rule should be:

RewriteEngine On
#
RewriteCond %{QUERY_STRING} ^cid=1259&pid=337$
RewriteRule ^categoryname$ http://www.new-example.com/category/pagename? [R=301,L]

Unfortunately, there appears to be no way to "automatically convert" all old URLs to new ones, since "cid=1259" does not give the "text" fof the new "category" and "pid" does not give the "text" for the new pagename. Therefore, the two main solutions are to add one rule for each cid/pid pair (which might result in an awful lot of rules) or to internally rewrite all requests to a script that has access to a database containing 'translations' of all important old URLs to new URLs. The script itself can then issue a 301-Moved Permanently redirect response header and a "Location" header specifying the new URL.

If you use this latter approach, make sure to include the server 301 status header and thoroughly test this code with a server headers checker such as the "Live HTTP Headers" add-on for Firefox/Mozilla browsers.

Jim