htaccess阻止一个特定的URL

问题描述:

我找不到此问题的解决方案。也许我使用了错误的搜索词? (htaccess阻止url,htaccess阻止单个url,阻止特定的htaccess阻止,...)

I could not find the solution to this question. Maybe I used the wrong search terms? (htaccess block url, htaccess block single url, block specific url htaccess, ...)

我有一个页面的URL像这样:

I have a page with a URL like this:

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

我想阻止此URL,因为不同的机器人(和人类)。

I would like to block this URL because different bots (and humans).

I在htaccess中尝试了以下规则:

I have tried the following rules within htaccess:

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

没有成功。

当有人请求时:

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

%{REQUEST_URI} 变量为:

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

和正则表达式 ^ 40224\ / $ wil我从不匹配。实际上,在这种情况下,您甚至不需要 RewriteCond ,只需将模式放在规则中即可:

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

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

请注意,规则本身的模式不会以 / 开头,这是因为规则将其删除,但是对于%{REQUEST_URI} var,它会保留。

Note that the pattern in the rule itself doesn't lead with a /, it's because for the rule, it's stripped off, but for the %{REQUEST_URI} var, it's preserved.