Re-route?

Discussion in 'PHP' started by le007, Sep 14, 2007.

  1. #1
    le007, Sep 14, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    RewriteEngine On
    RewriteRule ^register$ index.php?locate=register
    
    Code (markup):
    Save this as .htaccess in the same directory as index.php.
     
    nico_swd, Sep 14, 2007 IP
  3. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Hey nico - thanks very much for the reply.

    will this produce http://mywebsite.com/register

    ?
    Whats the ^register$ for?

    Will I save it as "register.htaccess" or what? Anything else need doing?

    Thanks again
     
    le007, Sep 14, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    No, save it as .htaccess, as I said.

    ^register$ is a pattern, that if matched, it will rewrite the URL to the wanted page.


    Just try it...
     
    nico_swd, Sep 14, 2007 IP
  5. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #5
    I did try it and it worked! Man you are superb! Thanks very much indeed!
    Do I ever need to set rewriteEngine Off?

    Also can I now add more in such as:

    RewriteRule ^register$ index.php?locate=register
    RewriteRule ^search$ index.php?locate=search

    etc?
     
    le007, Sep 14, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Yes you can. Either like you did above, or if you have multiple rewrites pointing to the same file, you can do:
    
    RewriteEngine On
    RewriteRule ^(register|search|etc|etc)$ index.php?locate=$1
    
    Code (markup):
     
    nico_swd, Sep 14, 2007 IP
  7. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #7
    $1 should that not be register?

    I found this on the net but I think yours is much easier to read and understand!
    RewriteEngine on
    Options +FollowSymlinks
    RewriteBase /

    RewriteRule ^([^/]+)/?$ index.php?local=$1 [QSA,L] # files in home dir only
     
    le007, Sep 14, 2007 IP