htaccess阻止一个特定的URL [英] Block one specific URL by htaccess

查看:430
本文介绍了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.

这篇关于htaccess阻止一个特定的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆