Don't want the query string to be appended

Oh, the strange things mod_rewrite does!

Don't want the query string to be appended

Postby longears » Thu Aug 30, 2007 12:53 pm

We just re-deployed a site, and want to redirect all the old pages to new ones. I have written a little over a hundred rules to handle this. However, if a user goes to a URL with a query string on the end, the Query string is passed to the new URL.

Here's one of my rules:

Code: Select all
RewriteRule ^Mens/c1/(.*)CAGE(.*)$ http://www.domain.com/store/dragon-sunglasses/ [R=301]


If a client goes to:
http://www.domain.com/Mens/c1/p395/CAGE-Jet-Grey-Fade-w/Grey-lens/index.html?sort=2a&page=23&language=en&action=buy_now

It redirects them to:
http://www.domain.com/store/dragon-sunglasses/?sort=2a&page=23&language=en&action=buy_now

I would like them to be redirected to:
http://www.domain.com/store/dragon-sunglasses/

Any clue?
longears
 
Posts: 12
Joined: Fri Jul 27, 2007 1:39 pm

Postby richardk » Thu Aug 30, 2007 4:02 pm

Add a ? to your new path.

You do not need to include the domain name and you should add the L flag.
Code: Select all
RewriteRule ^Mens/c1/.*CAGE.*$ /store/dragon-sunglasses/? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Perfect! Thank you!!

Postby longears » Fri Aug 31, 2007 5:47 am

Richard, thank you!
longears
 
Posts: 12
Joined: Fri Jul 27, 2007 1:39 pm

Postby htaccesselite » Fri Oct 05, 2007 2:55 am

I would also recommend adding the [NC]
htaccesselite
 
Posts: 6
Joined: Tue Nov 07, 2006 4:20 am
Location: http://groups.google.com/ group/apachehtaccess


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 2 guests

cron