Mod rewrite

Discussion in 'PHP' started by baris22, Sep 2, 2009.

  1. #1
    hello,

    I am trying for 2 hours now. i could not get this working.

    How can i turn this url:

    http://localhost/tv.php?page=$1

    to

    http://localhost/tv/index-1.htm

    thanks
     
    baris22, Sep 2, 2009 IP
  2. hasanrosidi

    hasanrosidi Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this one
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
    </IfModule>

    don't forget to activate mod_rewrite
     
    hasanrosidi, Sep 2, 2009 IP
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    it did not work.

    When i do this it works
    
    RewriteRule ^tv-(.*)\.htm$  tv.php?page=$1  [QSA,L]
    
    PHP:
    http://localhost/tv.php?page=$1
    to
    http://localhost/tv-1.htm

    but when i do this it does not work

    http://localhost/tv.php?page=$1
    to
    http://localhost/tv/index-1.htm

    
    RewriteRule ^tv/index-(.*)\.htm$  tv.php?page=$1  [QSA,L]
    
    PHP:
     
    baris22, Sep 2, 2009 IP
  4. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This works fine for me (looks like you needed a slash before tv.php but without it worked also on windows for me):

    RewriteEngine On
    RewriteRule ^tv/index-(.*)\.htm$  /tv.php?page=$1  [QSA,L]
    Code (markup):
     
    szalinski, Sep 3, 2009 IP
  5. hnida

    hnida Guest

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Some ppl would so be stuffed without these forums. Modrewrite is a big learning curve for something so simple.
     
    hnida, Sep 3, 2009 IP
  6. yuvrajm

    yuvrajm Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Simply:
    
    RewriteRule ^tv/index-([0-9]+)\.htm$  /tv.php?page=$1
    
    Code (markup):
     
    yuvrajm, Sep 4, 2009 IP