odd_duck
odd_duck

Reputation: 4111

301 Redirect Get Parameter URL with htaccess

I need to 301 redirect an old url that contained a get parameter in the url.

I need to 301 the URL:

http://www.website.com/choose?cat=womens

to this URL:

http://www.website.com/womens

I have searched and tried without it working:

RewriteCond %{QUERY_STRING} cat=womens
RewriteRule ^choose\.php$ /womens [L,R=301]

Where am I going wrong?

Upvotes: 1

Views: 999

Answers (2)

prj
prj

Reputation: 1

Try these:

RewriteCond %{QUERY_STRING} ^cat=womens$

RewriteRule ^choose$ http://www.website.com/womens? [R=301,L]

Upvotes: -1

anubhava
anubhava

Reputation: 786349

You're almost correct, just 2 issues:

  1. .php wasn't there in your original URI after choose as per the question
  2. You need to add ? in target to strip original query string

You can use:

RewriteCond %{QUERY_STRING} (?:^|&)cat=([^&]+) [NC]
RewriteRule ^choose(?:\.php)?$ /%1? [L,R=301,NC]

Upvotes: 2

Related Questions