2016-05-31 92 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。 –

相关问题