mod_rewrite and .htaccess

Discussion in 'Apache' started by cnapsys, Aug 8, 2011.

  1. #1
    hey all,
    I'm developing a new website in php/mysql and wanted to make sure that I build it using friendly urls.
    This is on a RHEL dedicated server with virtual hosting set up in Plesk.

    I've checked and mod_rewrite is on.

    I tried setting up a .htaccess file on the domain name.
    http://www.mydomain.com/new/

    .htaccess contents:

    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^browse/([0-9]+)\.html$ /browse.php?cat=$1

    Basically I want to make sure that the following link:
    http://www.mydomain.com/new/browse.php?cat=2
    is being rewritten to:
    http://www.mydomain.com/new/browse/2.html

    I have stopped > restarted apache but I am getting a 404.
    It seems that apache is completely ignoring the .htaccess file.

    Any help is greatly appreciated.

    c
     
    cnapsys, Aug 8, 2011 IP
  2. helpinghost

    helpinghost Active Member

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    53
    #2
    First important thing to remember is that .htaccess files are read on the fly. No need to restart Apache.
    Second, I think you are not escaping the / after browse and you are redirecting to /browse.php while I think the browse.php is within the new folder.
    Try it like this instead:

    RewriteRule ^browse\/([0-9]+)\.html$ browse.php?cat=$1
     
    helpinghost, Aug 9, 2011 IP
  3. cnapsys

    cnapsys Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yup.... that worked great. thank you very much
     
    cnapsys, Aug 12, 2011 IP