HTTP到HTTPS的完整路径和查询[apache]


http to https with full path and queries [apache]

抱歉,如果这个问题已经发布,但我搜索了两次。

我想把我的http://域名重定向到https://,也http:// example.com/homehttp:/ /www.example.com/homehttps://example.com/home

我谷歌,但不知道哪一个是完美的方式重定向。我使用这个工作,但只有当一个人访问http,如果有人直接打开https比接收错误这个页面有太多的重定向

。htaccess代码

Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)
http://www.newdomain.com%{REQUEST_URI} [R=302,NC]

我认为这是旧到新域名,但我不想重定向到另一个。将http重定向到https的域相同。

这是你的答案:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

或者使用:

RewriteEngine on
RewriteCond     %{SERVER_PORT} ^80$
RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]