【问题标题】:Redirect http to https exclude specific IP将 http 重定向到 https 排除特定 IP
【发布时间】:2017-06-13 20:52:30
【问题描述】:

我已使用以下规则排除 200.200.0.17 从 http 重定向到 https,但它的请求(来自 200.200.0.17)仍然被重定向到 https。任何帮助将不胜感激。

<VirtualHost _default_:80>
# If mod_rewrite is present, it takes precedence over mod_alias
# and it is necessary to rewrite the request to https.
  <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{REMOTE_ADDR} !^200.200.0.17
     RewriteRule (.*) https://%{HTTP_HOST}$1
  </IfModule>

# Otherwise use mod_alias to redirect.
  Redirect / https://%{HTTP_HOST}/
</VirtualHost>

【问题讨论】:

  • 我的回答对你有用吗?如果它确实使用了它左上角的勾号,请接受它。谢谢。

标签: apache .htaccess mod-rewrite http-redirect


【解决方案1】:

第一条规则执行后,第二条规则也执行。为防止这种情况发生,请使用last 标志。更改代码中的行:

RewriteRule (.*) https://%{HTTP_HOST}$1 [L]

见:https://httpd.apache.org/docs/2.4/rewrite/flags.htm

【讨论】:

    【解决方案2】:

    这是因为您设置了替代重定向,请删除:

    Redirect / https://%{HTTP_HOST}/
    

    或者它会在第一条规则忽略它之后继续重定向该 IP。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-07
      • 1970-01-01
      • 2014-03-17
      • 2014-12-28
      • 2014-02-06
      • 1970-01-01
      相关资源
      最近更新 更多