Mobile app version of vmapp.org
Login or Join
Debbie626

: Forbid users from accessing a long URL while allowing access to a shorter one with mod_rewrite I'm trying to block the following URL: www.example.com/Ayurveda/article/guna/alkalizing/contains/non-vegan/experience/relieves-burning

@Debbie626

Posted in: #Htaccess #ModRewrite

I'm trying to block the following URL:
example.com/Ayurveda/article/guna/alkalizing/contains/non-vegan/experience/relieves-burning

But I want to allow:
example.com/Ayurveda/article/guna/cold

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]

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Debbie626

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme