I'm trying to block the following URL:


But I want to allow:


I'm using the following code to match anything with 3 forward slashes after the word "article". The problem is that both of these URLs are returning "forbidden".

RewriteCond %{THE_REQUEST} ^(.*)Ayurveda/article/(.+)/(.+)/(.+)$ [NC,OR] 
RewriteRule .* - [F,L]

The %{THE_REQUEST} contains the full HTTP request header sent by the browser, not simply the URL. If you examine this value, you will see that for the second (short) URL, THE_REQUEST does in fact contain 3 forward slashes after the word "article" (although not necessarily part of the URL itself) and so matches the pattern. The request line is probably something like:

GET /Ayurveda/article/guna/cold HTTP/1.1

However, it will be much more efficient to specify the pattern in the RewriteRule instead, if possible. As it currently stands, .* will result in every request being processed by the ruleset.

So, maybe something like the following in .htaccess:

RewriteRule ^Ayurveda/article(/[^/]+){3,} - [F]

The L flag is implied when the F flag is used, so it is unnecessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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