How to redirect http to https and https://www to https://

时光怂恿深爱的人放手 提交于 2020-01-06 02:18:40

问题


I need help with rewrite rules.

So I want that these addresses:

http://domain.com
http://www.domain.com
https://www.domain.com

Redirect to:

https://domain.com

Can someone help me?

Right now I have rule:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]

But it doesnt redirect https://www to https://

回答1:


Place this rule in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} www\.
RewriteRule ^ https://domain.com%{REQUEST_URI} [L,R=301,NE]


来源:https://stackoverflow.com/questions/23297747/how-to-redirect-http-to-https-and-https-www-to-https

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