Forum Moderators: phranque
I wrote something but it doesn't work
RewriteEngine On
RewriteCond %{HTTP_REFERER}!^http://example.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.example.com/.*$ [NC]
RewriteCond %{REQUEST_METHOD}!^(GET¦HEAD¦POST) [NC,OR]
RewriteRule .* - [F]
[edited by: jdMorgan at 4:19 pm (utc) on Feb. 27, 2004]
[edit reason] Examplified URLs [/edit]
RewriteEngine On
RewriteCond %{HTTP_REFERER}!^http://(www\.)?example\.com/ [NC]
RewriteCond %{REQUEST_METHOD} ^POST [NC]
RewriteRule .* - [F]
I belive that blocking GET and HEAD requests that came without your referer is not what you want to do.
And also notify that .*$ or ^.* patterns make no sense.
[edited by: jdMorgan at 4:20 pm (utc) on Feb. 27, 2004]
[edit reason] Examplified URLs [/edit]
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www.)example.com/ [NC]
RewriteCond %{REQUEST_METHOD} ^POST [NC]
RewriteRule .* - [F]
[edited by: jdMorgan at 4:22 pm (utc) on Feb. 27, 2004]
[edit reason] Examplified URL, added double space [/edit]
Yes, there *should* be backslashes preceding any literal periods in your patterns.
Ref: [etext.lib.virginia.edu...]
Also, the meaning of (www\.)? is that the "www." may or may not be present in the request.
Do not add "/" to the end of your domain name; A port number, if added by a firewall or caching proxy, will go there, e.g. www.example.com:80/
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com [NC]
RewriteCond %{REQUEST_METHOD} ^POST$ [NC]
RewriteRule .* - [F]
I can guess, why the forum software swallows the space before the exclamation mark, as many people tend to inadvertently write You did it ! instead of (correctly) You did it!.
But: would it be possible to turn off this behaviour inside [code][/code]? This could save a lot of the hassle observed in this thread. The same happened to me before, although I recognized it and was able to correct my post.
Disallowing POST from other domains in general is okay if all your forms must work that way, but you should have measures that will prevent them from just doing a GET on the form script(s) in stead to get the result.