我想写作<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”?你在问什么? –