Reputation: 2976
Following problem: I have a form on a page and want to allow certain parameters to enable form value overwriting. But if there is a questionmark in the url without any of the parameter I want to redirect to the 404 page.
But my regex doesn't work very well...
RewriteCond %{QUERY_STRING} !^(a=.*|b=.*|c=.*)
RewriteRule ^subfolder/(.*)$ - [R=404,L,NC]
But now my page only shows up if a parameter is set. http://example.com/subfolder/ does not work, but http://example.com/subfolder/?a=whatever works. I only want a redirect if there is a question mark without any my parameters. How to do that?
Upvotes: 1
Views: 551
Reputation: 784918
You can use this rule:
RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !(^|&)(a|b|c)= [NC]
RewriteRule ^subfolder/(.*)$ - [R=404,L,NC]
First condition RewriteCond %{QUERY_STRING} .
makes sure that QUERY_STRING is non-empty.
Upvotes: 3