Reputation: 30501
I've been trying to work my head around this but my .htaccess powers just aren't as good as I thought. I have this sample query string:
http://mycoolsite.com/store.php?a=apples&type=fresh&b=banana
Is it possible to do this using .htaccess:
type=fresh
exists. If not then redirect to page index.phpUpvotes: 0
Views: 840
Reputation: 143926
You can use mod_rewrite to match against the query string. In your .htaccess:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)type=fresh&?(.*)$
RewriteRule ^(.*)$ /$1?%1%2 [L,R]
This will make it so if someone enters http://mycoolsite.com/store.php?a=apples&type=fresh&b=banana in the browser, their browser will get redirected to http://mycoolsite.com/store.php?a=apples&b=banana . If you want the redirect to happen internally (so the browser's location bar doesn't change), remove the ,R
in the brackets at the end of the RewriteRule.
Upvotes: 1