Forum Moderators: phranque
I've this set of rules in my .htaccess:
RewriteCond %{REQUEST_URI} somestring [OR]
RewriteCond %{QUERY_STRING} somestring
RewriteRule .* - [F,L]
If I key in "http://mysite.com/somestring" or "http://mysite.com/index.php?a=somestring", I'm redirected to the expected 403 Forbidden page.
If I key in "http://mysite.com?a=somestring", the URL is rewritten as "http://mysite.com/?a=somestring" and I'm redirected to the unexpected-at-all Apache test page.
As we say in French, "I give my tongue to the cat".
Thanks in advance,
Marino
Likely a problem with either "UseCanonicalName on" or the definition of DocumentRoot -- both in the server configuration file (for example, httpd.conf).
If you cannot correct the server configuration, you could try to correct the invalid slashless HTTP requests before doing your security test... like this:
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9} /[^\ ]*\ HTTP/
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
[i]RewriteCond $1 !^path-to-custom-403-error-page\.html$[/i]
RewriteCond $1 somestring [OR]
RewriteCond %{QUERY_STRING} somestring
RewriteRule (.*) /$1? [F]
This may be worth a try, especially if you do not have access to the server configuration files. Look at your server error log file if you have access to it.
Jim
I tried the rewriting part, but it did not work, though I know it should have. I also tried;
RewriteRule /\?(.*) http://example.com/spip.php?$1 [R=301]
And nope! Should have worked too...
So I tried:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /?\?([^\ ]*)\ HTTP/
RewriteRule .* http://example.com/spip.php?%1 [R=301]
and it worked.
Ok, now for the second part. What does the "$1" refers to? What is the need to RewriteRule (.*) /$1? [F] if the URL is to be forbidden?
[edited by: jdMorgan at 4:18 pm (utc) on Oct. 6, 2008]
[edit reason] Please use example.,com [/edit]
You can have a maximum of 9 such $ variables.
Likewise something in (brackets) on the RewriteCond line is bundled into %1 and can be re-used again.