开发者

htaccess for redirecting non-www to www while preserving http & https

开发者 https://www.devze.com 2023-03-16 19:01 出处:网络
My site just got its EV SSL certificate.In the past I\'ve redirected non-www requests to www using htaccess - and it worked well.

My site just got its EV SSL certificate. In the past I've redirected non-www requests to www using htaccess - and it worked well.

But now, if I request a https page, I end up (via the htaccess redirect) on the http version.

I need htaccess to redirect like this: non-www redirects to www, while preserving the http or https

Here is the htaccess file I'm using now:

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

It i开发者_运维技巧sn't working right. The https requests are being redirected to http.


Try this:

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301,QSA]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301,QSA]
0

精彩评论

暂无评论...
验证码 换一张
取 消