2016-06-21 75 views
2

堆栈溢出有许多类似的解决方案,如htaccess http to https with www. Without redirecting sub domain.htaccess HTTPS主域和通配符HTTP子域+所有非WWW

我需要什么,却是:

  • 主域HTTPS +非www
  • 通配符HTTP的所有子域,而不是加入了一个又一个。

我正在运行一个WordPress多站点网站,并且没有通配符SSL。

我使用的时刻如下:

非www

RewriteEngine on 
    RewriteBase/
    RewriteCond %{HTTP_HOST} www.(.*)$ [NC] 
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

非www和非HTTPS子域

RewriteEngine On 
    RewriteCond %{HTTPS} off 

    RewriteCond %{HTTP_HOST} !=subdomain1.main.com 
    RewriteCond %{HTTP_HOST} !=subdomain2.main.com 
    RewriteCond %{HTTP_HOST} !=subdomain3.main.com 
    RewriteCond %{HTTP_HOST} !=subdomain4.main.com 

SSL

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

回答

1

这是你想要的吗?

RewriteEngine On 
RewriteBase/

# www is redirected to base domain 
RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)$ 
RewriteRule ^(.*)$ https://%1/$1 [L,R=301] 

# base domain should use HTTPS 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^[^\.]+\.[^\.]+$ 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301] 

# other domain should use HTTP 
RewriteCond %{HTTPS} on 
RewriteCond %{HTTP_HOST} !^[^\.]+\.[^\.]+$ 
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301] 
+0

嗨弗洛里安,谢谢!不,它不起作用。当我添加它时,即使WWW被删除,所有内容都将转到HTTPS。 –

+0

我忘了在上面的评论中标记你。 –

相关问题