How can i create better urls using .htacces modrew

2019-08-25 19:05发布

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.

2条回答
【Aperson】
2楼-- · 2019-08-25 19:17

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

查看更多
在下西门庆
3楼-- · 2019-08-25 19:23

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.

查看更多
登录 后发表回答