2017-03-09 169 views
1

當我請求:顯示內容

subdomain1.domain.com 

i want to show the contents of /httpdocs/subdomain1/ 

當我要求

subdomain2.domain.com 

i want to show the contents of /httpdocs/subdomain2/ 

我想保持subdomain2.domain.com沒有重定向

我有一個通配符在我的Plesk,我只是不知道如何設置htaccess

我試過這個到目前爲止,b UT不工作

RewriteCond %{HTTP_HOST} !^www\. 
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ 
RewriteRule^http://subdomain.domain.com/%1%{REQUEST_URI} 

回答

1

不要使用http://的目標,否則,只要你想它會做一個完整的重定向不只是沉默重寫。

您可以使用:

RewriteEngine On 

RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.domain\.com$ [NC] 
RewriteRule^%1%{REQUEST_URI} [L] 

RewriteCond %{ENV:REDIRECT_STATUS} ^$將確保我們重寫一次。

+0

這給了我內部錯誤 –

+0

對不起,現在試試我更新的答案。 – anubhava

+0

謝謝!工作得很好! –