mod_rewrite blog post title - How to?

Discussion in 'PHP' started by fluid, Dec 17, 2006.

  1. #1
    I've checked quite a few tutorials on mod_rewrite but i'm still confused. If i create a .htaccess file with a mod_rewrite rule to redirect the page

    http://www.example.com/how-to-do-this

    to

    http://www.example.com/index.php?id=10

    Do i need to lookup the id for the post 'how-to-do-this' posted as a query string from the mod-rewrite rule in index.php and load the corresponding blog post? Also what will happen if i have 2 blog posts with the same title?

    Can somebody shed some light please?
     
    fluid, Dec 17, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You can rewrite the URL to this instead

    example.com/10/how-to-do-this

    or

    example.com/10-how-to-do-this

    This way you can get the ID and don't have to worry about anything else.
     
    nico_swd, Dec 17, 2006 IP
  3. alemcherry

    alemcherry Guest

    Best Answers:
    0
    #3
    alemcherry, Dec 17, 2006 IP
  4. fluid

    fluid Active Member

    Messages:
    679
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    70
    #4
    Thanks for the constructive feedback guys :)
     
    fluid, Dec 17, 2006 IP