简体   繁体   English

https非www重定向

[英]https non www redirect

I'm trying to get all my URLs to redirect to https:// without www. 我正在尝试让所有URL都重定向到不带www. https:// www.

If someone puts in www. 如果有人输入www. or http:// or http:// they are redirected to https:// the problem comes if they put https://www. http://http://重定向到https:// ,如果他们放置https://www. then it doesn't redirect to https://website 那么它不会重定向到https://website

I'm using the following in my htaccess , any suggestions? 我在htaccess使用以下内容,有什么建议吗?

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

This single rule can take care of both requirements: 这条规则可以满足以下两个要求:

RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]

Make sure to remove both of you shown rules and test in a new browser to avoid old cache. 确保删除两个显示的规则,并在新的浏览器中进行测试,以避免旧的缓存。

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

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