此問題通常來自使用相對URL的樣式表或JavaScript文件並將其與虛擬目錄結構相結合。如果你有這樣的重寫:
RewriteRule ^articles/(.*)$ articles.php
然後,你必須像網址:
http://example.com/articles/2011/03/14/title-of-the-article
其中包含HTML:
<link rel="stylesheet" type="text/css" href="css/general.css" />
不管你的文件artices.php
駐留在瀏覽器對瀏覽器不瞭解,因此mod_rewrite
的問題對瀏覽器一無所知。所以它會要求文件:
http://example.com/articles/2011/03/14/title-of-the-article/css/general.css
這顯然不存在。所以我建議指定URL的相對於你的web根目錄。例如:
<link rel="stylesheet" type="text/css" href="/css/general.css" />
請注意位於URL前面的/
。
請注意以下幾點:當您的網址以/
字符開頭時,表示相對於網頁的根目錄的路徑。看看這個例子directurey結構:
/
/index.html
/afolder
/afolder/stylesheets
/afolder/stylesheets/first.css
/afolder/stylesheets/second.css
/afolder/images
/afolder/images/a.jpg
/otherfolder
/otherfolder/something.html
什麼是您的CSS和JS文件的URL /路徑? – adarshr 2011-02-26 22:29:18
請向樣式表和Javascript文件顯示一些示例URL,以及嘗試直接訪問它們時出現的錯誤。 – 2011-02-26 22:29:30
我得到這個問題的最佳答案,你可以在這裏找到它:http://stackoverflow.com/questions/22689363/how-to-fix-resource-file-path-after-using-htaccess – nkarmi 2015-01-26 04:49:08