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

时间:2018-04-03 09:19:04

标签: .htaccess redirect https no-www

我想将我在我的网站example.com中拥有的所有网页重定向到https://www.example.com/ ..

在我的htaccess文件中,我的代码只能从所有http页面到https页面工作,但不能从非www页面到www页面工作(显示错误" 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]

适用于以下情况(每页.php):

http://example.com/page.phphttps://www.example.com/page.php http://www.example.com/page.phphttps://www.example.com/page.php

仅适用于以下情况(每页.php):

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

0 个答案:

没有答案
相关问题