.htaccess规则将所有内容重定向到https://那个东西

时间:2013-05-01 18:33:36

标签: .htaccess https

将用户的每个请求重定向到我的服务器上的任何页面到https://that page

的正确.htacess规则是什么

例如,mydomain.comhttp://mydomain.com会转到https://mydomain.com

此外,mydomain.com/projects/1.html会转到https://my domain.com/projects/1.html

无论请求的深度如何,来自浏览器的所有请求都是https://that location.

我该怎么做?

2 个答案:

答案 0 :(得分:1)

RewriteEngine on
RewriteRule (.*) https://mydomain.tld$1

确保vhost位于不同的文件夹中,因此显然不会递归。

答案 1 :(得分:1)

如果您使用的是Apache,则需要使用SSLRequireSSL指令来使用mod_ssl。 那么你需要使用mod_rewrite进行重定向。

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]