If is not localhost statement htaccess

岁酱吖の 提交于 2021-01-28 03:56:13

问题


i'm currently forcing visitors to access all my websites (mostly Wordpress) over https, witch i do with the following code:

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

Now i was wondering if i can use an if is not statement, so if i work on my local environment, this won't work. For example:

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

What's the best way to do this? Thanks is advance!


回答1:


http:// is not part of match in {HTTP_HOST} variable .You need to use !='localhost' If you are testing the on a local host or !='example.com' If testing this on example.com .

Full code

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


来源:https://stackoverflow.com/questions/50186811/if-is-not-localhost-statement-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!