Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a url forbidden in apache mod_rewrite, based on the query string?

How do I make the following url forbidden in apache;

main/index.php?site=ing

I have tried the following;

RewriteRule ^main/index.php?site=ing - [F]

but with no luck...

like image 501
jorgen Avatar asked Jul 06 '09 14:07

jorgen


People also ask

What is rewrite rule in Apache?

Summary. The mod_rewrite module uses a rule-based rewriting engine, based on a PCRE regular-expression parser, to rewrite requested URLs on the fly. By default, mod_rewrite maps a URL to a filesystem path. However, it can also be used to redirect one URL to another URL, or to invoke an internal proxy fetch.

What is PT in rewrite rule?

PT|passthrough If, for example, you have an Alias for /icons, and have a RewriteRule pointing there, you should use the [PT] flag to ensure that the Alias is evaluated. Alias "/icons" "/usr/local/apache/icons" RewriteRule "/pics/(.+)\.jpg$" "/icons/$1.gif" [PT]

What is rewrite rule in htaccess?

htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.


2 Answers

You cannot match a query string in the RewriteRule, you have to do

RewriteCond %{QUERY_STRING} site=ing     #Adjust the regexps with anchors
RewriteRule ^main/index.php - [F]
like image 130
Vinko Vrsalovic Avatar answered Oct 06 '22 23:10

Vinko Vrsalovic


This should do it:

RewriteCond %{QUERY_STRING} (^|&)site=ing(&|$)
RewriteRule ^main/index\.php$ - [F]
like image 27
Gumbo Avatar answered Oct 06 '22 22:10

Gumbo