我有一個共享主機,它將主域 - mydomain.com 和一個子域 - beta.mydomain.com - 指向同一個檔案夾 public_html。
這個主機的結構是:
/
a
b
public_html
-a
-b
-.htaccess
foldera和binsidepublic_html指向根目錄中的相應檔案夾。
在.htaccess檔案中,有以下規則:
RewriteEngine on
#Subdomain rule#
RewriteCond %{HTTP_HOST} ^beta.mydomain.com$
RewriteRule ^(.*)$ /b/otherfolder/$1 [NC,L]
#Main domain rule#
RewriteCond %{REQUEST_URI} !^/a
RewriteRule ^(.*)$ /a/otherfolder/$1 [NC,L]
實際上,當我訪問主域時,主域規則匹配并顯示正確的頁面。
當我訪問子域時,子域規則匹配并回傳錯誤 500;但是,洗掉$1on /b/otherfolder/$1,它會顯示該檔案夾上的索引檔案(當然,該頁面無法加載正確的 js 或 css 檔案)。
問題:
我怎樣才能避免錯誤 500 并讓
Subdomain rule另一個作業和另一個作業一樣好?How can I enable the error log for the server/htaccess? I read about the ErrorLog directive, however my search only referred to the PHP.
uj5u.com熱心網友回復:
500因為無限回圈,你得到了。發生這種情況是因為子域重寫是無條件的,因為它不斷重寫為/b/otherfolder/.
你可以有以下規則:
RewriteEngine on
#Subdomain rule#
RewriteCond %{HTTP_HOST} ^beta\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/b/ [NC]
RewriteRule ^(.*)$ b/otherfolder/$1 [NC,L]
#Main domain rule#
RewriteCond %{REQUEST_URI} !^/(a|b)/ [NC]
RewriteRule ^(.*)$ a/otherfolder/$1 [NC,L]
請注意添加了一個條件RewriteCond %{REQUEST_URI} !^/b/ [NC],當 URI 以/b/.
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/449237.html
標籤:apache .htaccess mod-rewrite
下一篇:301重定向結構的重寫規則
