Need help on my mom rewrite please

Discussion in 'PHP' started by RyanDoubleyou, Jun 4, 2008.

  1. #1
    EDIT** I know the title is spelled wrong, no need to tell me about it again. Can a moderator please change it?

    Hello all,
    I own tackypenguin.com and I need help on a mod rewrite problem.

    Right now I have the following code on my .htaccess file
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^/([a-zA-Z]+)$ /index.php?page=$1
    RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)$ /index.php?page=$1&do=$2
    </IfModule>
    Code (markup):
    Basically, I want it to take tackypenguin.com/user or any other word, and make it get tackypenguin.com/index.php?page=user or whatever word.

    Then, I would like it to have two directories, like tackypenguin.com/user/login and make it get tackypenguin.com/index.php?page=user&do=login.

    Right now when I try to do this, if i go to tackypenguin.com/user, it gives me my 404 error.
    Any help would be greatly appreciated.
     
    RyanDoubleyou, Jun 4, 2008 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    when you get the 404 error, what page cannot be found?
     
    crath, Jun 4, 2008 IP
  3. RyanDoubleyou

    RyanDoubleyou Peon

    Messages:
    86
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I put in tackypenguin.com/user

    It should be getting tackypenguin.com/index.php?page=user

    My index.php page has my design, then it uses include to add in the content from user.php. it says that tackypenguin.com/user/ cannot be found, which means my mod rewrite is not working somehow. because it thinks tackypenguin.com/user/ is a real directory.
     
    RyanDoubleyou, Jun 4, 2008 IP
  4. Lucas3677

    Lucas3677 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try removing the "/" from the first RewriteRule:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^([a-zA-Z]+)$ /index.php?page=$1
    RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)$ /index.php?page=$1&do=$2
    </IfModule>
    Code (markup):
     
    Lucas3677, Jun 4, 2008 IP
  5. RyanDoubleyou

    RyanDoubleyou Peon

    Messages:
    86
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for trying, but this didn't work.
     
    RyanDoubleyou, Jun 4, 2008 IP
  6. Lucas3677

    Lucas3677 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Try this code:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^([a-zA-Z]+)/?$ /index.php?page=$1
    RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)/?$ /index.php?page=$1&do=$2
    </IfModule>
    Code (markup):
    I added a check to make sure the requested file doesn't exist (in which case it wouldn't redirect to index.php), and added testing for optional trailing slashes in the URL.
     
    Lucas3677, Jun 4, 2008 IP
  7. RyanDoubleyou

    RyanDoubleyou Peon

    Messages:
    86
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you sooo much. This fixed it. This was bugging me so much, but now its fixed! Once again, thank you.
     
    RyanDoubleyou, Jun 4, 2008 IP