mod_rewrite user account redirect

Discussion in 'Apache' started by casper, May 26, 2006.

  1. #1
    Hey everyone,

    I have created a website where users may register for webspace. I would like them to access their webspace via www.website.com/john , rather than www.website.com/website.php?user=john which of course doesn't look very pretty.

    I'm using the following code:

    At least this code redirects every request to website.php instead of pointing to a non existing folder, but it's not passing on the GET variables.

    When I place a simple echo $_GET['user']; inside website.php , the script outputs website.php and not the username john I requested. Does anyone know why it is not working properly?

    thx casper
     
    casper, May 26, 2006 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    You have to edit the script so it adds the '?user=whatever' part to the URL.

    Post in the php board.

    Or, if you're trying to make the links point to the new URL, you have to edit the part of the php file that creates the links. mod_rewrite only makes the URLs work.
     
    Nintendo, May 26, 2006 IP
  3. casper

    casper Guest

    Messages:
    181
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thx for replying, Nintendo :) .

    However, I think that mod_rewrite could take care of this problem without modifying the PHPfile. This tutorial is using the same method with the difference that the tutorial code is actually working.

    I know that I'm doing something wrong, since the htaccess file should redirect to website.php?user=john , instead of website.php?user=website.php
     
    casper, May 26, 2006 IP
  4. casper

    casper Guest

    Messages:
    181
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    whoa got it :)

    RewriteEngine on
    RewriteRule ^([A-Za-z0-9_]+)/?$ website.php?user=$1 [T=application/x-httpd-php,L]
    RewriteRule ^([A-Za-z0-9_]+)/([A-Za-z0-9_]+)/?$ website.php?user=$1 [T=application/x-httpd-php,L]
     
    casper, May 26, 2006 IP