.htaccess mod_rewrite question

Discussion in 'Search Engine Optimization' started by irunbackwards, Oct 25, 2006.

  1. #1
    I am not really familiary with mod_rewrite at all ...

    How can I add code to my .htaccess file that will change a url like this:

    http://upload.gnomeproblem.com/index.php?file=23745-bloodelfmounts.png
    Code (markup):
    into this:

    http://upload.gnomeproblem.com/files/23745-bloodelfmounts.png
    Code (markup):

     
    irunbackwards, Oct 25, 2006 IP
  2. sundaybrew

    sundaybrew Numerati

    Messages:
    7,294
    Likes Received:
    1,260
    Best Answers:
    0
    Trophy Points:
    560
    #2
    Maybe like that , not sure , Nintendo is the master

    RewriteRule ^files/([_A-Za-z0-9-]+)/?$ /index.php?file=23745$1 [NC,L]
     
    sundaybrew, Oct 25, 2006 IP
  3. irunbackwards

    irunbackwards Peon

    Messages:
    791
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    that did it perfectly! thanks!

    can u explain to me how that works so i can do it for other sites on my own? thanks
     
    irunbackwards, Oct 25, 2006 IP
  4. sundaybrew

    sundaybrew Numerati

    Messages:
    7,294
    Likes Received:
    1,260
    Best Answers:
    0
    Trophy Points:
    560
    #4

    Just change the files/ to what ever you want the word/ to be then followed by the index.php?=whatever your string is

    Like -------->>>>RewriteRule ^keyword/([_A-Za-z0-9-]+)/?$ /index.php?file=23745$1 [NC,L]
     
    sundaybrew, Oct 25, 2006 IP
  5. irunbackwards

    irunbackwards Peon

    Messages:
    791
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    errrr scratch that its not working.. i thought it was :( heres what i put in my htaccess

    RewriteEngine on
    RewriteRule ^files/([_A-Za-z0-9-]+)/?$ /index.php?file=$1 [NC,L]
     
    irunbackwards, Oct 25, 2006 IP
  6. irunbackwards

    irunbackwards Peon

    Messages:
    791
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I changed it to this:

    RewriteRule ^files/(.*)$ index.php?file=$1

    and it worked
     
    irunbackwards, Oct 25, 2006 IP