如何创建使用.htacces modrewrite更好网址 [英] How can i create better urls using .htacces modrewrite
问题描述
这是我的网址正确nowm我的产品
This are my urls right nowm for my products
http://www.example.com/product.php?product=32723
我想实现这个
http://www.example.com/product/32723-brand-模型产品名
我一直在修改我的.htaccess但真的就如何实现这一目标没有头绪。
I have been modifying my .htaccess but really with no clue on how to achieve this.
推荐答案
您必须将网址与的 重写规则
模式和重写到目标URL
You must match your URL with a RewriteRule
pattern and rewrite it to the target URL
RewriteRule ^/product/(\d+)- /product.php?product=$1
这个模式匹配开头 /产品/
的任何URL,并抓住了以下数字(\ d +)
之后破折号 -
。替换URL将是 /product.php?product =
与所捕获的数字 $ 1
追加。
This pattern matches any URL starting with /product/
and captures the following digits (\d+)
followed by a dash -
. The substitution URL will be /product.php?product=
with the captured digits $1
appended.
要捕捉比赛的某些部分,你将它用括号(...)
。了解更多关于在mod_rewrite的在 URL重写简介经常使用前pressions - 普通防爆pressions 。
To capture some part of the match, you enclose it in parenthesis (...)
. Read more on regular expressions used in mod_rewrite at Apache mod_rewrite Introduction - Regular Expressions.
这篇关于如何创建使用.htacces modrewrite更好网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!