2012-05-16 27 views
0

我想用扁平連接這樣的:的.htaccess扁平鏈

http://somedomain.com/about-us 
http://somedomain.com/products-list 
http://somedomain.com/product/item  

因此我用mod_rewrite規則是這樣的:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^([0-9A-Za-z-]+)?$ /index.php?page=$1 [L] 
    RewriteRule ^([0-9A-Za-z-]+)/([0-9A-Za-z-]+)?$ /index.php?page=$1&value=$2 [L] 
</IfModule> 

前兩個環節工作正常。但每當我訪問第三種類型的鏈接圖像或CSS或任何JS鏈接作爲相對路徑腳本,例如。 <img src="images/image.jpg"><a href="about-us">About Us</a>

瀏覽器認爲它在http://somedomain.com/product/images/image.jpghttp://somedomain.com/product/about-us

正確的路徑應該是http://somedomain.com/images/image.jpghttp://somedomain.com/about-us

並由此與文件相對鏈接不工作。

如何解決這個問題?我不想爲所有鏈接文件使用完整路徑而不是相對路徑。通過在的.htaccess

回答

0

嘗試逃離你的斜線做一些調整,請提出一個方法:

RewriteRule ^([0-9A-Za-z-]+)\/([0-9A-Za-z-]+)?$ /index.php?page=$1&value=$2 [L] 
+0

感謝@克里斯您的快速反應。 但它仍然無法正常工作。瀏覽器仍然認爲相對路徑不在根目錄下。 **相關鏈接不工作**。 如上所述,它仍然鏈接爲_http://somedomain.com/product/images/image.jpg_ NOT _http://somedomain.com/images/image.jpg_ –