htaccess for redirecting non-www to www while pres

2020-04-19 21:47发布

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 isn't working right. The https requests are being redirected to http.

标签: .htaccess
1条回答
虎瘦雄心在
2楼-- · 2020-04-19 22:26

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]
查看更多
登录 后发表回答