![](/img/trans.png)
[英]htaccess eliminate www then redirect all non subdomains traffic to https
[英]Redirect ALL traffic to https including subdomains and remove www
我正在尝试使用以下规则创建一个 .htaccess 文件:
http://www.example.com/test => https://example.com/test
http://test.example.com/test => https://test.example.com/test
https://www.example.com/test => https://example.com/test
这是我当前的 .htaccess 文件:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.nebla.co.uk$ [NC]
RewriteRule ^(.*)$ http://nebla.co.uk/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
然而,这会导致一些奇怪的行为:
http://www.nebla.co.uk/ => https://nebla.co.uk/public_html
它还会导致子域上的重定向循环。
我设法通过而不是使用来解决我的行为
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.nebla.co.uk$ [NC]
RewriteRule ^(.*)$ http://nebla.co.uk/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
我将$1
更改$1
%{REQUEST_URI}
例如:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.nebla.co.uk$ [NC]
RewriteRule ^(.*)$ http://nebla.co.uk/%{REQUEST_URI} [R=301,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.