Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect without query string

I'm trying to redirect (note without query strings):

http://www.reviews.com/review/review_review.cfm?review_id=135223

to

http://www.reviews.com/

The current rule:

Redirect 301 /review/review_review.cfm http://www.reviews.com/

Causes the original URL to redirect to http://www.reviews.com/?review_id=135223

Based on a few stack questions here and here, I should be able to add a ? to the Redirect rule as below:

Redirect 301 /review/review_review.cfm http://www.reviews.com/?

but this redirects to http://www.reviews.com/?. The trailing ? remains. How do I get rid of this it's killing me.

like image 864
Justin Avatar asked Mar 01 '13 04:03

Justin


1 Answers

You can't get rid of the extraneous ? using mod_alias. The ? will prevent a query string from getting appended but with mod_alias, it unfortunately includes a ? as part of the redirect. However, mod_rewrite won't, because adding the ? to the end, which tells it to not include any existing query string, works the same way as mod_alias, but after that it gets processed again by mod_alias, minus the trailing ?, so the end result is no trailing ? at the end of the URL. So something like:

RewriteEngine On
RewriteRule ^/?review/review_review.cfm$ http://www.reviews.com/? [L,R=301]

And this would replace the Redirect statement.

like image 135
Jon Lin Avatar answered Nov 10 '22 00:11

Jon Lin