Help with Mod_Rewrite

Discussion in 'Apache' started by Strike X, Apr 16, 2009.

  1. #1
    I am trying to get URL working for SEO. ID and Title should be included.

    domain.com/news.php?id=12 to domain.com/news/12/tite-of-news
    domain.com/news.php to domain.com/news.php

    However if someone type: domain.com/news/12/
    and ignore the tile.. it should still work.

    This is what I have done:
    RewriteRule ^news/([0-9]+)$ news.php?id=$1 [L]
     
    Strike X, Apr 16, 2009 IP
  2. Strike X

    Strike X Active Member

    Messages:
    162
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I managed to get it working using: RewriteRule ([0-9]+)/(.*) news.php?id=$1 [L]

    Is that correct way?
     
    Strike X, Apr 16, 2009 IP
  3. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, this is a correct way to do it.

    I would add the ^news/ part back as you had in the first attempt. No reason to leave that out ;)

    Hope this helps.
     
    Lpe04, Apr 20, 2009 IP