Creating dynamic URLs in htaccess

前端 未结 3 1619
遇见更好的自我
遇见更好的自我 2020-12-18 08:40

I\'m trying to write an .htaccess file that will make my URLs more attractive to search engines. I know basically how to do this, but I\'m wondering how I could do this dyna

3条回答
  •  执念已碎
    2020-12-18 09:16

    At the moment you're wondering how to convert your ugly URL (e.g. /view.php?mode=prod&id=1234) into a pretty URL (e.g. /products/product-title). Start looking at this the other way around.

    What you want is someone typing /products/product-title to actually take them to the page that can be accessed by /view.php?mode=prod&id=1234.

    i.e. your rule could be as follows:

    RewriteRule ^products/([A-Za-z0-9-])/?$ /view.php?mode=prod&title=$1
    

    Then in view.php do a lookup based on the title to find the id. Then carry on as normal.

提交回复
热议问题