2017-02-22 122 views
0

我需要指向(不重定向)子域到根域中的目錄。比如我有以下領域:PHP .htaccess點子域到根目錄中,不需要重定向

https://test.example.com 

我想,要指向的目錄:

https://example.com/apple 

這需要在不脫離子域更改URL的情況發生。這也需要包括任何URL參數,例如:

https://test.example.com/hello-world 

應該指向(不定向)到:

https://example.com/apple/hello-world 

在我.htaccess文件(在子域的根目錄下),我有:

RewriteEngine on 
RewriteBase/
RewriteCond %{HTTP_HOST} ^test\.example\.com$ 
RewriteCond %{REQUEST_URI} !^/apple$ 
RewriteRule ^(.*)$ https://example.com/apple/$1 

這個工作,但它重定向。有關如何在不使用重定向的情況下將子域指向該目錄的任何建議,請使用mod_proxy

+0

的[htaccess的重寫子域到目錄]可能的複製(http://stackoverflow.com/questions/10642426/htaccess-rewrite-subdomain-to-directory) –

+0

@ ponury-kostek所有這些都重定向 –

回答

0

嘗試下面的規則我假設這兩個域指向相同的位置。

RewriteEngine on 
RewriteBase/
RewriteCond %{HTTP_HOST} ^test\.example\.com$ 
RewriteRule ^(.*)$ apple/$1 [L] 
+0

謝謝。我更新了我的問題,我可能無法打開mod_proxy(這是一個共享服務器)。 –