使用 htaccess 阻止 URL

Block URL with htaccess

如何通过 htaccess 阻止以 'select-a-plan.html' 结尾的 URL? 我试过了

RewriteRule ^/select-a-plan.html$ - [F]

RewriteCond %{REQUEST_URI} ^/select-a-plan.html
RewriteRule ^(.*)$ - [F,L]

没有成功

根据您展示的示例,请您尝试以下操作。 请在测试您的 URL 之前清除您的浏览器缓存。

RewriteEngine ON
RewriteRule select-a-plan\.html/?$ - [NC,F]

修复了 OP 的漂亮尝试:

  1. 首先,当使用 RewriteRule 匹配时,它永远不会从 / 开始,您的正则表达式 ^/ 将不会在此处匹配。
  2. 我已经使用 NC apache 的 FLAG 来启用 ignorecase 以匹配任何大小写文件名。
  3. 此外,由于字符串 select-a-plan.html 将位于 uri 的最后,因此我们不需要首先使用 ^(caret),因为它假定我们从 uri 的开头匹配它。