htaccess REDIRECT https://example.com TO https://www.example.com

孤者浪人 提交于 2019-12-23 02:39:27

问题


I'd like to redirect all the pages that I have in my site example.com into https://www.example.com/..

In my htaccess file I have this code that works only from all the http pages to https pages but doesn't work from non-www pages to www pages (shows error "ERR_CONNECTION_REFUSED").

Options -MultiViews
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. 
RewriteCond %{HTTPS}s on(s)|offs() 
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]

# Redirect to HTTPS 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Works in these cases (each of pages .php) from:

http://example.com/page.php to https://www.example.com/page.php http://www.example.com/page.php to https://www.example.com/page.php

Doesn't work only in these cases (each of pages .php) from:

https://example.com/page.php to https://www.example.com/page.php

来源:https://stackoverflow.com/questions/49626411/htaccess-redirect-https-example-com-to-https-www-example-com

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