所以我有 2 個站點,只需呼叫它們example.com和admin.example.com.
example.com列在我的 cPanel 中,檔案根目錄為/home/username/public_html(不可更改),但實際檔案存盤在home/username/example-site 中。admin.example.com與檔案 root home/username/public_html/admin一起列出。
目錄結構:
home/username
|- example-site
|...
|- public_html
|- admin
這兩個站點是用不同的框架構建的。現在,如果沒有正確的 .htaccess 檔案,當我嘗試訪問example.com它時會顯示 public_html 檔案夾中的檔案串列,并且admin.example.com作業正常。
因此,我正在嘗試使用 .htaccess 檔案將我的檔案根目錄example.com從/home/username/public_html 移動到/home/username/example-site,但我似乎找不到適合我需要的正確格式。有任何想法嗎?
uj5u.com熱心網友回復:
我建議您將檔案夾“example-site”移動到檔案夾“public_html”中(您可能還想重命名它):
home/username
|...
|- public_html
|- example-site
|- admin
然后您實作一個重寫規則,將所有未將管理子域指定為 http 主機的請求映射到該檔案夾??中:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^admin\.example\.com$
RewriteCond %{REQUEST_URI} !^/example-site/
RewriteRule ^ /example-site%{REQUEST_URI} [L]
作為替代方案,您還可以實作一個積極的條件:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteCond %{REQUEST_URI} !^/example-site/
RewriteRule ^ /example-site%{REQUEST_URI} [L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/326432.html
