【问题标题】:If is not localhost statement htaccess如果不是 localhost 语句 htaccess
【发布时间】:2018-05-05 07:16:40
【问题描述】:

我目前正在强制访问者通过 https 访问我的所有网站(主要是 Wordpress),我使用以下代码:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

现在我想知道是否可以使用 if is not 语句,所以如果我在本地环境中工作,这将不起作用。例如:

<If "%{HTTP_HOST} != 'http://localhost:8888'">
    # live configuration 
</If>
<Else>
    # local configuration 
</Else>

最好的方法是什么? 谢谢提前!

【问题讨论】:

    标签: .htaccess ssl localhost


    【解决方案1】:

    http:// 不是{HTTP_HOST} 变量匹配的一部分。如果您在本地主机上测试,则需要使用!='localhost',如果在example.com 上测试,则需要使用!='example.com'

    完整代码

     <If "%{HTTP_HOST} != 'localhost'">
    # live configuration
    </If>
    <Else>
    # local configuration 
    </Else>
    

    【讨论】:

      猜你喜欢
      • 2016-06-05
      • 2013-09-08
      • 2018-05-05
      • 1970-01-01
      • 2013-07-13
      • 2012-12-26
      • 2013-06-20
      • 2013-09-04
      • 1970-01-01
      相关资源
      最近更新 更多