我有一個網站運行在localhost/pm
和RewriteBase正確設置爲/pm/
。我的文檔中有一個鏈接標籤:<link ... href="themes/default/css/default.css">
。基本的URL重寫:如何有一個CSS鏈接,IMG SRC等,忽略它?
當url爲localhost/pm
或localhost/pm/foo
時,CSS正常工作。但是,如果URL中有更多斜線,則樣式表更改爲foo/themes/default/css/default.css
時,將顯示相對URL localhost/pm/foo/bar
。
如何在不必在鏈接標記中添加某種PHP路徑分辨率的情況下使其工作?
# invoke rewrite engine
RewriteEngine On
RewriteBase /pm/
# Protect application and system files from being viewed
RewriteRule ^(?:system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
編輯:
基本上我現在需要的是這樣的: 如果請求中包含的文件夾名稱/themes/
廢料一切,這是/themes/
之前,其餘改寫爲/pm/themes/...
我想它是這樣的: RewriteRule ^.*(/themes/.*)$ /pm/themes/$1
但我得到一個內部服務器錯誤。爲什麼?
如果我不喜歡這樣寫道:RewriteRule ^.*(/themes/.*)$ /pm/themes/
(即只是刪除從最終$ 1)並使用URL http://localhost/pm/foo/themes/foo/
所產生的物理位置是http://localhost/pm/themes
這是什麼太期待,這反過來又意味着,至少在我的正則表達式是正確。我錯過了什麼?
您必須排除使用RewriteCond重寫css,請參閱此答案http://stackoverflow.com/a/15348786/1741542或重寫CSS請求,請參閱http://stackoverflow.com/a/15535329/1741542 – 2013-03-23 17:20:51
沒有幫助。然而,使用 標籤。 –
2013-03-23 17:37:59
使用'base'標籤時請注意,有關詳細信息,請參閱http://stackoverflow.com/q/1889076/1741542。如果你的css文件位於'/ pm/themes/default/css /'下面,你也可以重寫這些文件。 – 2013-03-23 17:53:58