【问题标题】:htaccess RewriteCond not working after forcing https强制https后htaccess RewriteCond不起作用
【发布时间】:2017-09-21 00:59:06
【问题描述】:

我有一些规则拒绝从某些 IP 地址访问联系表单,如下所示

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

#restrict access to contact form
RewriteCond %{REQUEST_URI} ^.(index.php/)?contact(.*) [NC]
RewriteCond %{REMOTE_ADDR} ^81\.136\.137\.239
RewriteRule ^(.*)$ / [F,L]

在我将 https 重写限制在联系表单之前工作正常。 在将所有流量强制到 https 后,我什至可以从特别受限的 IP 地址访问联系表单。

REQUEST_URI 行中是否存在未获取 https 连接的内容? (如果可能,我希望它限制对 http 和 https 的访问,但如果不是,则仅限制 https)

【问题讨论】:

  • 我可能会感到困惑,不管http&https,你想限制这个IP只访问联系人文件夹吗?
  • 还有其他 IP,但我只展示了一个作为示例。我想限制通过 https 和 http 访问联系表

标签: .htaccess mod-rewrite https


【解决方案1】:

转到文件夹并制作.htaccess并将以下代码放入其中:

deny from 81.136.137.239

如果你有更多的 IP 像上面的例子一样添加它们

更新

如果是文件试试这个:

RewriteEngine On

RewriteCond %{REQUEST_URI}  contact
RewriteCond %{REMOTE_ADDR} ^81\.136\.136\.239 
RewriteRule ^(.*)$ / [F,L]

更多IP:

    RewriteEngine On
    RewriteCond %{REQUEST_URI}  contact
    RewriteCond %{REMOTE_ADDR} ^81\.136\.136\.239  [OR]
    RewriteCond %{REMOTE_ADDR} ^81\.136\.136\.230  [OR]
    RewriteCond %{REMOTE_ADDR} ^81\.136\.136\.220
    RewriteRule ^(.*)$ / [F,L]

【讨论】:

  • 没有联系人文件夹 - 这是一个动态 URL。 htaccess 位于站点根目录中。
  • 为什么 "RewriteCond %{REQUEST_URI} contact" 可以在 https 上工作,而 "RewriteCond %{REQUEST_URI} ^.(index.php/)?contact(.*) [NC]" 不行?
猜你喜欢
  • 2019-09-08
  • 2016-05-24
  • 2013-04-06
  • 1970-01-01
  • 2018-10-26
  • 1970-01-01
  • 2023-03-29
  • 2015-01-28
  • 2015-01-27
相关资源
最近更新 更多