I'm trying to limit which characters can be used in the request URI using:

RewriteEngine on

RewriteCond %{REQUEST_URI} !^([a-z0-9\:\/\.\_\-]) [NC]

RewriteRule ^.* - [F,L]

For some reason it's not working. Any ideas?

Thanks!

link|improve this question

Rather than creating that sort of filter yourself you might want to take a look at mod_security (modsecurity.org). – joschi Dec 10 '10 at 12:04
feedback

1 Answer

up vote 2 down vote accepted
+50

Nice question. A good way to protect against XSS (cross site scripting).

This is the solution:

            RewriteEngine on
            RewriteCond %{REQUEST_URI} [^a-z0-9\_\:\/\.\-] [NC]
            RewriteRule () - [F,L]

A shorter equivalent would be:

            RewriteEngine on
            RewriteRule [^a-z0-9\_\:\/\.\-] - [F,L]
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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