尝试使用重写规则解决此问题,例如,该子规则将子域分配给同名的根目录。重写链接规则,冲突的文件和文件夹
ddd.example.com会链接到“/ _projects/ddd”目录,工作正常,我没有问题,问题是我在根目录“/”中的任何文件或目录都可以从子域ddd.example.com访问。
下面是一个例子的目录结构
example.com = “/”
- “的index.php”
ddd.example.com = “/ _projects/ddd”
个
- 没有文件
所以,如果比如我访问ddd.example.com/index.php,这将解决使用文件位于example.com/index.php这是在下面找到一个目录。
这里是的.htaccess
# Skip rewrite if subdomain is www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain to %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com(:80)?$
# Redirect to domain if requested URL does not resolve to existing subdirectory path
RewriteCond %{DOCUMENT_ROOT}/_projects/%1 !-d
RewriteRule (.*) http://example.com/ [NC,R=301]
# Skip rewrite if subdomain is www
RewriteCond %{HTTP_HOST} !^www\. [NC]
# Extract (required) subdomain to %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com(:80)?$
# Skip rewrite if requested URL does not resolve to existing subdirectory path or file
RewriteCond %{DOCUMENT_ROOT}/_projects/%1/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/_projects/%1/$1 -d
RewriteRule (.*) /_projects/%1/$1 [NC,L]
回复是位于下方。 – Upperfoot 2012-03-17 14:04:34