2016-03-31 37 views
0

我需要幫助(內部重定向?)使用Apache的htaccess。htaccess:子域到服務器上的文件夾。保持URL

在我的服務器我有一個主域

網址:domain.com
服務器的路徑:/opt/public_html/domain.com/

子域

url:sub.domain.com
服務器的路徑:/opt/public_html/sub.domain.com/

當訪問者類型sub.domain.com我想要的網址將保持不變。我還希望服務器向訪問者提供文件/opt/public_html/domain.com/index.php。我如何在.htaccess中做到這一點?

另外,如果訪問者輸入sub.domain.com/sofa/,則服務器應該在不更改URL的情況下爲文件/opt/public_html/domain.com/sofa/index.php提供服務。

Got it? OK最後一個例子:

如果訪問者類型sub.domain.com/?big=mac服務器應該顯示文件/opt/public_html/domain.com/?big=mac而不更改URL。

任何想法如何做到這一點?

+0

對不起?所以訪問'http:// sub.domain.com'會轉到'/ public_html/sub.domain.com /',而'http:// sub.domain.com/sofa'會轉到'/public_html/domain.com /沙發/ index.php'?這很奇怪! –

+0

否。如果'http:// sub.domain.com'則是'/ public_html/domain.com /',如果是'http:// sub.domain.com/sofa',那麼'/public_html/domain.com/sofa/index.php'(或'/ public_html/domain.com/sofa /'無關緊要) – Ralle

+0

但是在你的問題中你沒有這樣說? –

回答

1

如果您啓用RewriteEngine在您的.htaccess中,您應該能夠創建一個條件和規則來處理在子域URL中服務主域的頁面。事情是這樣的:

RewriteEngine on 
RewriteBase/
RewriteCond %{HTTP_HOST} sub.domain.com$ 
RewriteCond %{REQUEST_URI} !^/sub.domain.com 
RewriteRule .* domain.com/%1 [L] 

RewriteCond線,使該規則適用於任何網頁在sub.domain.com,應該從public_html/sub.domain.com送達。它應該(希望在內部)將URI更改爲http://domain.com/whatever而不在瀏覽器中進行更改。

查看this questionthis one瞭解類似的信息。如果.htaccess真的不適合你,你可以嘗試代理,mod_rewrite或創建符號鏈接。

相關問題