Forum Moderators: phranque

Message Too Old, No Replies

Please double check my rewrites

         

Nutter

10:04 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



I'm moving a bunch of articles from one site to another and then want any other requests to the old site to redirect to the index page of the new site. I've got the rewrites done ok for the original articles moving to their new locations, but I want to double check that I'm doing the 'anything else' rewrite, and in the correct place.

RewriteRule ^article1 http://www.example.com/new_article_1.html [R=301,L,QSA]
RewriteRule ^article2 http://www.example.com/new_article_2.html [R=301,L,QSA]
...and so on...

# Rewrite for everything else
RewriteRule ^(.*)$ http://www.example.com [R=301,L,QSA]

Does this look about right? I figure if it gets through all the individual rewrites, the last one will catch everything else.

edit: I intentionally left off the $ of the individual article rewrites so it catches article1-page1, article-page2, etc.

jdMorgan

5:10 pm on Jan 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are not appending additional query string parameters, so what is the [QSA] flag for?

Your last rule will redirect to itself (infinite loop) unless you use a RewriteCond to prevent it.

JIm

Nutter

8:12 pm on Jan 16, 2006 (gmt 0)

10+ Year Member



The QSA - The old site was running a CMS that had urls being rewritten to be more friendly. When the redirects took place, the query string still went with it to the new site. QSA fixed it for me, although I imagine there's a better way.

The infinite loop - The original site is subdomain.example1.com and is going to redirect to www.example2.com. The rewrite for that is on the subdomain.example1 site. I don't think that'll cause a loop, although I certainly could be wrong.

jdMorgan

3:23 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to clear the query string, simply append a "?" to the substitution URL, rather than using [QSA] -- It's quite a it more efficient:

RewriteRule ^article1 http://www.example.com/new_article_1.ht[b]ml?[/b] [R=301,L]
RewriteRule ^article2 http://www.example.com/new_article_2.ht[b]ml?[/b] [R=301,L]
...and so on...
# Rewrite for everything else
RewriteRule ^(.*)$ http://www.example.c[b]om?[/b] [R=301,L]

The appended "?" will not appear in the new URL - it only serves to clear the query when it is followed by a blank.

Jim