在我的單頁面webapp中,我使用了html5歷史API,以便網址可以具有REST模式(/ section1/stuff1 ..),並且我正在計劃根據url路徑,使某種JavaScript路由器導航到頁面的幾個部分。在.htaccess中編寫規則以匹配正確的圖像文件夾位置
現在我還在本地服務器(WAMP)上,我增加了一個.htaccess文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php/$1 [L]
到應用程序根目錄包含的頁面的某些章節引用該URL的路徑(例如,子域/章節N)總是可以重定向到的index.php和重定向成功但所有外部ressources未能加載和我得到:
Resource interpreted as Image but transferred with MIME type text/html: "http://localhost/subdomain/section1/images/imgname.gif".
,它的邏輯,因爲圖像文件夾位於應用程序根一個d不在/section1
文件夾下,而.htaccess規則RewriteRule (.*) index.php/$1 [L]
應僅取/images/imgname.gif
部分,並在http://localhost/subdomain/
後面進行協調。
我發現this作爲一個類似的問題,所以我重寫.htaccess文件是這樣的:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?section1/(.+)$ index.php/$1
RewriteRule (.*) index.php/$1 [L]
,但我得到了500 Internal Server Error
。
我將[L]從最後一行移到上一行,但仍然得到了500錯誤,因爲實際上這兩個規則都是重定向所必需的,因爲即使url http:// localhost/subdomain/section1應該由規則處理在最後一行(RewriteRule(。*)index.php/$ 1)中,因爲section1本身只是DOM的一個子元素而不是頁面。 – Bardelman
改變最後兩行的順序並沒有解決它,因爲它看起來像一旦處理了第一個RewriteRule(RewriteRule(。*)index.php/$ 1),它就不會將手伸向下一個規則。 – Bardelman
我犯了一個錯誤;它不是我需要的串行處理,但是RewriteRule^/?section1 /(.+)$ index.php/$ 1規則應該只處理某些文件擴展名(.png,.jpg,..)特定的url。怎麼可能? – Bardelman