繁体   English   中英

.htaccess-从www https重定向到非www https

[英].htaccess - redirect from www https to non www https

我有.htaccess:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1 [R=302,NE,L]

当我从(例如)重定向时,它正常工作:从http://重定向到正确的https://从http:// www重定向到正确的https://但当我有https:// www时 我没有重定向和“非信任连接”。

我应该在htaccess文件中进行哪些更改?

只需在第二条规则上也重定向到https,例如

RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=302,NE,L]

无关,但是您无需捕获路径,只需使用REQUEST_URI

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM