How can i create better urls using .htacces modrewrite

柔情痞子 提交于 2019-12-11 20:44:01

问题


This are my urls right nowm for my products

http://www.example.com/product.php?product=32723

I want to achieve this

http://www.example.com/product/32723-brand-model-productname

I have been modifying my .htaccess but really with no clue on how to achieve this.


回答1:


You must match your URL with a RewriteRule pattern and rewrite it to the target URL

RewriteRule ^/product/(\d+)- /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.

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.




回答2:


This question is so common I just put up the whole answer with code here:

http://www.prescia.net/bb/coding/5-141018-simple_friendly-url



来源:https://stackoverflow.com/questions/26695446/how-can-i-create-better-urls-using-htacces-modrewrite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!