KingRichard
KingRichard

Reputation: 1244

.htaccess redirect if URL contains GET value

I have a BIG problem... a marketing 'expert' sent out a campaign with the wrong link. Instead of linking to a landing page, it links to our 'About Us' page.

I'm trying to figure out how to redirect the link using .htaccess. I can't just redirect all traffic to that page, or our about us page becomes useless. The url contains GET parameters that I figured I could use like this:

302 Redirect ^www\.mysite\.com\/wrong\-page\/?get_param=sandwich&get_bread=bolillo-roll ^www\.mysite\.com\/correct\-page\/?get_param=sandwich&get_bread=bolillo-roll

This has no effect. Maybe a small syntax error I'm missing? Or perhaps the parameters are messing it up? Any suggestions are appreciated.

Upvotes: 2

Views: 274

Answers (1)

anubhava
anubhava

Reputation: 785176

You can't match query string like that. Use mod_rewrite rules instead:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^get_param=sandwich&get_bread=bolillo-roll [NC]
RewriteRule ^wrong-page/?$ /correct-page [L,NC,R=302]

QUERY_STRING will be automatically carried over to new URL.

Upvotes: 1

Related Questions