.htaccess - redirect from www https to non www https

天大地大妈咪最大 提交于 2020-01-17 06:17:29

问题


I have .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. I don't have redirection and "non trusted connection".

What I should change in my htaccess file?


回答1:


Just redirect to https on your second rule too, e.g.

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.



来源:https://stackoverflow.com/questions/37642550/htaccess-redirect-from-www-https-to-non-www-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!