Htaccess重定向与https和子域

时间:2014-08-13 20:18:00

标签: apache .htaccess mod-rewrite redirect

我有htaccess:

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]

将http重写为https并添加" www"。但我想从我的子域重定向:

http://subdomain.mysite.com => https://www.mysite.com
https://subdomain2.mysite.com => https://www.mysite.com

等。 我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

请改为尝试:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ https://www\.mysite\.com/$1 [L,R=301]