2012-11-28 17 views
0

我想讓我的網址乾淨。下面是我想做的事:
骯髒的網址:www.site.com/index.php?page=products
清潔網址:www.site.com/products/使用Apache mod_rewrite時<a>標記中href屬性的正確形式是什麼?

對於這一點,我寫在.htaccess文件這些代碼:

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/

RewriteRule ^([^/]*)/$ /index.php?page=$1 

但每當我點擊鏈接在我的項目中,我重定向到localhost頁面。鏈接是這種形式:

<a href="products">Products</a> 

我認爲這可能與href值。
什麼是href價值的正確形式? href="product"href="/product/"等。 ?

回答

1

沒有爲您的href屬性,以不同的方式每個窗體行爲沒有正確的形式:

<a href="products">Products</a> 

以上會從你目前的頁面比較去,所以可能是domain.com/products但可能是domain.com/shop/products

您更好地使用從根目錄下有一個鏈接通過在開始使用/,例如:

<a href="/products">Products</a> 

會去domain.com/products(注意在URL的末尾缺少/,這將使它無法與您當前的htaccess規則工作)

爲了使雙方/products/products/到正確的位置,改變你的htaccess裁定:

RewriteRule ^([^/]*)/?$ /index.php?page=$1 

?會使它前面的可選角色,所以在這種情況下,/

+0

謝謝@尼克爲您提供寶貴的答案。請告訴我,對於我所說的,「RewriteBase /」有沒有任何作用? –

+0

正如我把'?'標記,當我想要午餐網站時,我重定向到本地主機:( –

相關問題