2016-05-31 93 views
0

我希望通過htaccess動態地將子域指向子目錄,而無需更改下面的URL和目錄列表。子域通過htaccess動態指向子目錄而無需更改網址

|-- Test (Root Directory) <-- test.com redirects to this folder. 
|-- index.php 
| 
|-- subdomain (Directory) 
| 
|---- abc (Directory) <-- abc.test.com redirects to this folder. 
|------ index.php 
| 
|---- pqr (Directory) <-- pqr.test.com redirects to this folder. 
|------ index.php 
| 
|---- xyz (Directory) <-- xyz.test.com redirects to this folder. 
|------ index.php 

我已經應用以下重寫規則指向子域。

.htaccess文件

RewriteEngine On 

RewriteCond %{HTTP_HOST} ^www.test.com 
RewriteRule (.*) http://test.com/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} ^test\.com $ 
RewriteCond %{REQUEST_URI} !^/subdomain/ 
RewriteRule (.*) /subdomain/$1 

RewriteCond %{HTTP_HOST} ^(^.*)\.test.com 
RewriteCond %{REQUEST_URI} !^/subdomain/ 
RewriteRule (.*) /subdomain/$1 

我不是htaccess的重寫那麼多好。

我必須遵循這個subdomain on the fly

但我不能成功。您的建議非常感謝。

謝謝。

回答

0

希望這將有助於

RewriteEngine on 

RewriteCond %{HTTP_HOST} ^www.test.com 
RewriteRule (.*) http://test.com/$1 [R=301,L] 

RewriteCond %{HTTP_HOST} !^www\. 
RewriteCond %{HTTP_HOST} ^([^\.]+)\.test\.com$ [NC] 
RewriteRule ^(.*)$ http://test.com/subdomain/%1/$1 [L,NC,QSA] 
+0

謝謝您的答覆。但我想在不更改任何網址的情況下執行此操作。對於例如test.com指向根目錄,abc.test.com指向abc(子文件夾),但不更改url。 –

+0

您的域名是通配域名嗎?如果沒有,你需要在你的DNS服務器上設置 – ASR

+0

我在我的DNS服務器上設置了* .test.com。 –

相關問題