![](/img/trans.png)
[英]Htaccess Redirect: WWW + HTTPS://WWW + HTTP:// ---> HTTPS://non-www
[英]Redirect www and http to non-www with https using .htaccess
我已将以下内容写入我的.htaccess文件,该文件位于index.html所在的目录中。
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URL} [L,R=301]
I want that
www.example.com
http://example.com
and http://www.example.com
are redirected to
https://example.com
我必须与example.com交换REQUEST_URI还是做其他错误的事情?
您必须在重写条件之间放置一个OR
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
注意:您必须将网址测试为:
他们都将被重定向到
https://example.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.