.htaccess - redirect from www https to non www htt

2019-09-15 19:06发布

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条回答
Ridiculous、
2楼-- · 2019-09-15 19:45

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.

查看更多
登录 后发表回答