如果在相對URL的開頭有一個/
,那麼它將被解析爲域的Web根目錄的絕對路徑。
實施例絕對路徑(有/開頭):
在domain.com/test/other/path/test.html
href="/design/layout.css"
文件
- >瀏覽器搜索在domain.com/design/layout.css
在域中的文件/的test.html
href="/design/layout.css"
- >瀏覽器搜索在domain.com/design/layout.css
結論ABSOLU te路徑
瀏覽器在同一地點搜索兩次。
實施例的相對路徑(無/開頭):
在domain.com/test/other/path/test.html
href="design/layout.css"
文件
- >瀏覽器搜索在domain.com/test/other/path/design/layout.css
在域中的文件/的test.html
href="design/layout.css"
- >瀏覽器搜索在domain.com/design/layout.css
結束語相對路徑
瀏覽器在不同地方搜索。
解決方案
您可以添加在你的.htaccess或.conf文件一Apache Alias,請求第一路徑時,這會強制服務器輸出的第二路徑的內容。在你的情況下,Apache輸出來自新路徑的CSS文件,而不是/ design/。Apache的別名
例
Alias /design /your/new/path/design
非常感謝你 – samoyed 2011-05-13 07:14:34