Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have this url:

mysite.com?var=var&var2=var2&var3=var3

I would like to block this specific url but not in any way affect other query strings on the same base url.

Is it possible to do this?

Thanks,

share|improve this question
add comment

1 Answer

You can use ModRewite to check for query strings and redirect or block a page. Using your example:

RewriteCond %{QUERY_STRING} var=var
RewriteCond %{QUERY_STRING} date=12/12/12
RewriteCond %{QUERY_STRING} var2=word\+word
RewriteRule .* - [F]

(There's an implicit AND between the RewriteCond statements)

This would block ([F]) all pages (.*) that had all three of those querystring parameters and values.

UPDATED to use more specific examples by the OP

share|improve this answer
    
Perfect, thanks! –  rix Dec 20 '11 at 15:58
    
Actually, that doesn't appear to work - any other ideas? –  rix Dec 20 '11 at 16:16
1  
It worked in my local Apache install. Is RewriteEngine On? What happens when you hit the URL above? –  lvmisooners Dec 20 '11 at 16:19
    
@rix Keep in mind that there may be characters in your string that need to be escaped with a ` when used in a regex. If this doesn't work, try setting a RewriteLog` and turn RewriteLogLevel to 9, and let us know what that gives you. –  Shane Madden Dec 20 '11 at 16:22
    
Ah right, I have / in the var ie a date=12/12/12 and other than that just + for spaces. ie var=word+word - does the + and the / need to be escaped? –  rix Dec 20 '11 at 16:30
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.