嘗試使用重寫規則解決此問題,例如,該子規則將子域分配給同名的根目錄。重寫鏈接規則,衝突的文件和文件夾
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