简体   繁体   English

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

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

I have .htaccess: 我有.htaccess:

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

It works ok when I have redirection from (example): from http:// is redirect to correct https:// from http://www is redirect to correct https:// but when I have https://www . 当我从(例如)重定向时,它正常工作:从http://重定向到正确的https://从http:// www重定向到正确的https://但当我有https:// www时 I don't have redirection and "non trusted connection". 我没有重定向和“非信任连接”。

What I should change in my htaccess file? 我应该在htaccess文件中进行哪些更改?

Just redirect to https on your second rule too, eg 只需在第二条规则上也重定向到https,例如

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

Not related, but you don't need to capture the path, only use REQUEST_URI . 无关,但是您无需捕获路径,只需使用REQUEST_URI

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

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