[英].htaccess mod_rewrite: Force https and www, but not for local
Thanks to the people of Stack Overflow I have the following in my htaccess to force www and https in URLs. 多亏了Stack Overflow的人们,我的htaccess中有以下内容可以强制在URL中使用www和https。 It forks fine:
它很好:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) https://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
Now - for my local enviroment - I want to exclude a URL of the form "local.name.de" 现在-对于我的本地环境-我想排除形式为“ local.name.de”的URL
According to this post Apache mod_rewrite: force www only if not in localhost I added the following line: 根据这篇文章Apache mod_rewrite:仅当不在本地时才强制www我添加了以下行:
RewriteEngine on
RewriteCond %{HTTP_HOST} !=local #new line
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) https://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
but it does not work. 但它不起作用。 I also tried this without success:
我也尝试了这个但没有成功:
RewriteCond %{HTTP_HOST} !=local.name.de
Could you help me on this? 你能帮我吗? Thanks
谢谢
At the end, this works: 最后,这有效:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^local
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*) https://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^local
RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.