使用.htaccess为子域名添加https

时间:2014-08-28 05:26:51

标签: .htaccess mod-rewrite url-rewriting subdomain

我有两个子域名,例如schools.mydomain.co.ukadmin.mydomain.co.uk,我需要为两个域的所有请求网址添加https://,我已将.htaccess更改为如下所示这两个子域指向同一个根文件夹。 但是gettiong错误"此网页有一个重定向循环"

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^admin\.mydomain\.co\.uk [NC]
RewriteRule (.*) https://admin.mydomain.co.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^schools\.mydomain\.co\.uk [NC]
RewriteRule (.*) https://schools.mydomain.co.uk/$1 [R=301,L]

1 个答案:

答案 0 :(得分:1)

您没有检查是否已使用HTTPS访问它们:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTPS} ^off
RewriteCond %{HTTP_HOST} ^(admin|schools)\.mydomain\.co\.uk [NC]
RewriteRule (.*) https://%1.mydomain.co.uk/$1 [R=301,L]