2016-03-03 19 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的幻想網站。 –

相關問題