我想寫作<a href="product.php?id=5">
作爲產品/ 5.我不是在談論用戶輸入doamin.com/product/5才能得到結果,我要找的是 - 當用戶點擊鏈接時,瀏覽器地址欄將顯示url爲domain.com/product/5。用變量重寫url
是否有可能?任何幫助將不勝感激。提前感謝。
我想寫作<a href="product.php?id=5">
作爲產品/ 5.我不是在談論用戶輸入doamin.com/product/5才能得到結果,我要找的是 - 當用戶點擊鏈接時,瀏覽器地址欄將顯示url爲domain.com/product/5。用變量重寫url
是否有可能?任何幫助將不勝感激。提前感謝。
只要寫:
<a href="/product/5">LINK</a>
什麼你還需要一個的.htaccess文件,即處理mod_rewrite的,例如:
# turn mod_rewrite engine on
RewriteEngine On
# rewrite all physical existing file or folder
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
# allow things that are certainly necessary
RewriteCond %{REQUEST_URI} "/css/" [OR]
RewriteCond %{REQUEST_URI} "/images/" [OR]
RewriteCond %{REQUEST_URI} "/images/" [OR]
RewriteCond %{REQUEST_URI} "/javascript/"
# rewrite rules
RewriteRule .* - [L]
RewriteRule (.*) index.php?_route=$1 [QSA]
有了,你會得到一個$ _GET ['_ route']這將是價值將/產品/ 5。其餘的由你的php代碼來解析這個字符串。
非常感謝,它的工作正常。 因爲我是這個領域的新手,只是爲了知識 - 這是做這種方法的安全方法嗎?我是這樣想着正確的方向來處理$ _get []嗎?我聽說它對SEO很好。並且如果你可以推薦一些好的文章來增益。再次感謝。 – user1187405
此方法與「?id = 5」一樣安全。它取決於你,如何「安全」地處理你得到的變量。它肯定會提高你的搜索引擎優化,它也將使分享你的鏈接更容易。想象一下在手機上:「嘿,夥計們,看看這個:domain.com/product=128e947dje747」或只是「domain.com/redshirt」:)但不要過頭。諸如「/ Red-Shirt-With-Sprinkles-And-Blue-Neck-By-Company」這樣的域名不會增加可讀性和SEO。作爲最後的提示:在您的網址中使用「 - 」而不是「_」,因爲谷歌更喜歡這個。如果你想進一步的信息搜索「mod_rewrite」,「乾淨的網址」,「S」「...... :) – insertusernamehere
....將href位置更改爲「/ product/5」?你在問什麼? –