.htaccess redirect issue

Discussion in 'Programming' started by theonlymo, Apr 20, 2014.

  1. #1
    I am trying to have domain.com/game/tetris rewrite to domain.com/game.php?keyword=tetris , but it doesn't seem to be working. My line of code is below. Can anyone see what I am doing wrong?

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/game/(.*)$ /game.php?keyword=$1 [NC,L]​

     
    theonlymo, Apr 20, 2014 IP
  2. tylerman169

    tylerman169 Member

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    43
    #2
    Here is what the .htaccess should contain to do the redirect you are requesting:

    RewriteEngine On
    RewriteRule ^game/(.*) /game.php?keyword=$1 [L]
    Code (markup):
    You can test that it is working by checking out this site:

    http://htaccess.madewithlove.be/
     
    tylerman169, Apr 21, 2014 IP
  3. theonlymo

    theonlymo Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Thanks, it worked on the test page, but just not on my actual site. I even tried removing all other rewriterules and only using the code you wrote, but it still wont work. Its just not meant to be.
     
    theonlymo, Apr 21, 2014 IP
  4. jasonlimwk

    jasonlimwk Active Member

    Messages:
    121
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    how about setting this to your htaccess

    Redirect 302 /domain.com/game/tetris/index.html http://www.domain.com/game.php?keyword=tetris
     
    jasonlimwk, Apr 21, 2014 IP
  5. theonlymo

    theonlymo Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    The only version of the code that will work is:
    1. RewriteEngine On
    2. RewriteRule ^(.*) /game.php?keyword=$1 [L]
    But if I add the /game/ subdirectory it doesn't work.
     
    theonlymo, Apr 21, 2014 IP
  6. tylerman169

    tylerman169 Member

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    43
    #6
    Is the .htaccess file in the root directory?
     
    tylerman169, Apr 22, 2014 IP