htaccess, Redirect all requests to https://www [closed]

北战南征 提交于 2019-12-12 07:24:07

问题


Using .htaccess, I need to redirect all requests from

http://www.domain,
http://domain,
https://domain

to;

https://www.domain.com

How would I do this? I don't have any subdomains.


回答1:


RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] 
RewriteCond %{http_host} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]    

That will direct all HTTP requests to https://www.example.com as well as redirect https://example.com to https://www.example.com.




回答2:


Try this one...

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTPS_HOST} ^domain.com$
RewriteRule ^(.*)$ "https\:\/\/www\.domain\.com\/$1" [R=301,L]


来源:https://stackoverflow.com/questions/6085740/htaccess-redirect-all-requests-to-https-www

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