Rewrite URLs with names from database

Discussion in 'PHP' started by Web Gazelle, Jan 21, 2009.

  1. #1
    I have urls such as -> products.php?category=38

    How would I rewrite these Urls to something like -> products/modern-lighting
    ("Modern Lighting" would be the category name which comes from the database table for category 38)

    I understand how to do basic url rewriting with the htaccess, but I'm stumped on how to turn that number '38' into its category name.

    Does anyone have an idea?
     
    Web Gazelle, Jan 21, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    in your php page which links to products.php?category=38 add via a mysql query to extract title of the category with id 38 something like products.php?category=38&catname=modern-lighting then rewrite with mod_rewrite
     
    crivion, Jan 21, 2009 IP
    Web Gazelle likes this.
  3. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #3
    You will need to have a programmer look into the code and tweak it. Also, you have not mentioned anything about what software you are using? Are you use some custom-made software or some openly available software such as Zencart, OsCommerce, etc? Did you check the settings section of the software to see if there is an option for such links?
     
    rohan_shenoy, Jan 21, 2009 IP
  4. Web Gazelle

    Web Gazelle Well-Known Member

    Messages:
    3,590
    Likes Received:
    259
    Best Answers:
    0
    Trophy Points:
    155
    #4
    Thanks, crivion, I did exactly what you mentioned then tweaked it a bit. That method works great. Problem solved. Thanks.
     
    Web Gazelle, Jan 21, 2009 IP
    buffalo likes this.
  5. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #5
    Just a note, if your category name is not the primary key, you will need to index it to avoid overheads in your table.
     
    Kaizoku, Jan 21, 2009 IP