2016-02-27 110 views
1

我需要重定向我的子域重定向子域名域名,並保持URL

http://sub.domain.com

http://domainB.com/news

我嘗試了各種後一切在ht中的可能性訪問沒有任何結果。

此代碼工作正常,但是從域rediret,而不是從子域...

RewriteCond %{HTTP_HOST} ^domain.com$ 
RewriteRule ^(.*) https://subdomain.domainB.com/$1 [P] 

此代碼重定向domain.com到

https://subdomain.domainB.com

,並保留域.com在地址欄中並正常工作。我想子域名subdomainB。

我需要幫助。

在此先感謝;)

回答

1

你需要匹配反對的RewriteCond子域。

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ 
RewriteRule ^(.*)$ https://subdomain.domainB.com/$1 [P] 
+0

將這個代碼在文檔根目錄?或者在子域文件夾中? –

+0

這會返回一個錯誤代碼500 –

+0

代碼沒問題,代碼中沒有任何內容會導致500錯誤。請檢查您的錯誤日誌,以獲取有關錯誤 – starkeen

1

除了由starkeen答案,你應該添加SSLProxyEngine On使用SSLEngine on到Apache的設置時,或者這將引發內部服務器錯誤(500):

SSLEngine on 
SSLProxyEngine On 
SSLCertificateFile /etc/ssl/XXXXX_webserver_ssl.crt 
SSLCertificateKeyFile /etc/ssl/XXXXX_webserver_ssl.key 

RewriteCond %{HTTP_HOST} ^sub\.domainA\.com$ 
RewriteRule ^(.*)$ https://subdomain.domainB.com/$1 [P,L]