Block one specific URL using htaccess

I could not find a solution to this issue. Maybe I used the wrong search terms? (URL of htaccess block, separate htaccess block URL, specific htaccess block URL, ...)

I have a page with this URL:

https://www.mathelounge.de/40224/redaktionelle-frage-wann-antwort-wann-lediglich-kommentar

I would like to block this URL because there are different bots (and people).

I tried the following rules in htaccess:

 RewriteCond %{REQUEST_URI} ^40224\/$ [NC] RewriteRule .* - [F] 

to no avail.

+7
source share
1 answer

When someone asks:

 https://www.mathelounge.de/40224/redaktionelle-frage-wann-antwort-wann-lediglich-kommentar 

Variable %{REQUEST_URI} :

 /40224/redaktionelle-frage-wann-antwort-wann-lediglich-kommentar 

And the regex ^40224\/$ will never match that. In fact, you don’t even need a RewriteCond in this case, just put the template in the rule:

 RewriteRule ^40224/redaktionelle-frage-wann-antwort-wann-lediglich-kommentar$ - [F] 

Please note that the template in the rule itself does not lead to / because it is deleted for the rule, but for %{REQUEST_URI} it is saved.

+13
source

Source: https://habr.com/ru/post/951494/


All Articles