How to achieve this redirection using .htaccess

Discussion in 'Apache' started by deepesh, Feb 26, 2008.

  1. #1
    deepesh, Feb 26, 2008 IP
  2. maiahost

    maiahost Guest

    Messages:
    664
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Something like this should do the trick :
    
    RewriteRule ^([-_a-zA-Z0-9]+).html$ /myscript.php?url=$1 [L]
    
    Code (markup):
     
    maiahost, Feb 26, 2008 IP
  3. deepesh

    deepesh Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Thanks, I will try and post back.
     
    deepesh, Mar 11, 2008 IP
  4. vmihaylov

    vmihaylov Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    In my opinion the previous example is not correct.
    What you need to check whether the file exists, and if it does not pass the whole URI as a parameter to the php script

    RewriteEngine On
    # check if requested file exists
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    # if not, pass it to index.php
    RewriteRule ^(.*) index.php?page=$1 [QSA] # QSA preserves the query
     
    vmihaylov, Mar 12, 2008 IP
  5. deepesh

    deepesh Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Thanks, It worked :)
     
    deepesh, Mar 14, 2008 IP