Use apache to block a url with specific query string
11,427
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
Related videos on Youtube
Author by
rix
Updated on September 18, 2022Comments
-
rix almost 2 years
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,
-
rix over 12 yearsActually, that doesn't appear to work - any other ideas?
-
Scott Coldwell over 12 yearsIt worked in my local Apache install. Is RewriteEngine On? What happens when you hit the URL above?
-
ravi yarlagadda over 12 years@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 turnRewriteLogLevel
to 9, and let us know what that gives you. -
rix over 12 yearsAh 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?
-
Scott Coldwell over 12 yearsThe
+
needs to be escaped:RewriteCond %{QUERY_STRING} var=word\+word