rewriting url with mod_rewrite

Discussion in 'Apache' started by itssangy, Dec 14, 2007.

  1. #1
    I was reading few articles on mod_rewrite, and it gave me a huge headache, so I'm posting my question hoping someone can answer so I can learn from the example :D

    i have a site with multiple pages all referred to by index.php?page=name
    i would like to be able to goto

    domain.com/home
    domain.com/news

    and have it redirect to:
    domain.com/index.php?page=home
    domain.com/index.php?page=news


    any help is greatly appreciated
     
    itssangy, Dec 14, 2007 IP
  2. MakeADifference

    MakeADifference Peon

    Messages:
    476
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    Create .htaccess file on your server (under main folder or document root) with the following entries:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^([^/]+)?$ index.php?page=$1

    This is telling the apache that anything followed by the domain name, whihc is not slash (/), should go to index.php with page name parameter...!!
     
    MakeADifference, Dec 14, 2007 IP
  3. itssangy

    itssangy Peon

    Messages:
    135
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks i'll give that a wirl
     
    itssangy, Dec 14, 2007 IP