3

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,

6

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

5
  • 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? – Scott Coldwell 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
  • The + needs to be escaped: RewriteCond %{QUERY_STRING} var=word\+word – Scott Coldwell Dec 20 '11 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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