2016-03-03 72 views
1

我有以下HTTP地址:如何将HTTP重新连接到HTTPS与子域?

http://www.example.com/ 

但我HTTPS地址都有一个子也没有WWW,像这样:

https://secure.example.com/ 

我尝试以下规则:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://secure.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
</IfModule> 

差我来:

https://secure.www.example.com/ 

如何强制HTTPS在这种情况呢?因为我需要删除www。


编辑:我的上方都有这些规则 '花哨的网址' 为我使用WordPress作为CMS:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

回答

1

这应该是你的完整的htaccess:

RewriteEngine On 
RewriteBase/
#1--Redirect "http://domain to "https://secure" 
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://secure.domain.com%{REQUEST_URI} [L,R=301] 

#2--wp rules--# 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
+0

谢谢,但不幸的是,人们不知道该子域,因为它只用于与HTTPS。 –

+0

你想将主站点重定向到子域吗? – starkeen

+0

是的。我希望将主要网站'http:// www.'重定向到'https:// secure.',同时保持WordPress规则适用于花哨的URL(请参阅OP中的编辑)。在此先感谢:) –

1
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://secure.example.com/$1 [L,R=301] 
</IfModule> 

OR

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://secure.example.com/$1 [R=301,L] 

两个规则做到这一点:任何非https请求被重定向到https://secure.example.com,同时保留整个网址

+0

它适用于网页,而不是其他的链接。可能与我已经设置的规则有关。 –

+0

删除所有规则,只是离开我的。尝试第一个,如果你不喜欢它尝试第二个,但不要尝试它们,他们正在做同样的事情。 –

+0

不幸的是,这打破了WordPress的幻想网站。 –