.htaccess - 通过 htaccess 阻止一个特定的 URL

标签 .htaccess

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

我有一个带有如下 URL 的页面:
https://www.mathelounge.de/40224/redaktionelle-frage-wann-antwort-wann-lediglich-kommentar
我想阻止这个 URL,因为不同的机器人(和人类)。

我在 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\/$永远不会匹配。事实上,您甚至不需要 RewriteCond在这种情况下,只需将模式放入规则中:
RewriteRule ^40224/redaktionelle-frage-wann-antwort-wann-lediglich-kommentar$ - [F]

请注意,规则本身中的模式不会以 / 开头。 ,这是因为规则,它被剥离了,但对于%{REQUEST_URI} var,它被保留了下来。

关于.htaccess - 通过 htaccess 阻止一个特定的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18173693/

相关文章:

html - 在 .htaccess 中重写引擎以捕获不以 html 结尾的文件

php - 如何在 PHP 中使用 HTTP 身份验证,然后针对数据库运行输入的数据?

apache - mod_rewrite 的隐藏功能

apache - 使用 S3/EC2 时删除 ".php"文件扩展名

javascript - 从使用 React 和 Webpack 构建的网站的 url 中删除 .html 扩展名

regex - 在 .htaccess 中从 URL 中删除单词

php - 域映射不适用于 Linux 虚拟主机

javascript - 图片或 JS 未在 Magento 2 安装中显示

wordpress - 为什么我在 mod_pagespeed 中得到 PNG 的 404

html - 在您的根目录中有一个索引页面是否至关重要,例如 index.html、index.php