Mod_rewrite Query String

Discussion in 'Apache' started by THT, Oct 19, 2009.

  1. #1
    I have urls like this:
    
    WxW.domain.com/picture/subfolder/showpic.htm?img=blah.jpg
    
    Code (markup):
    id like urls like:

    
    WxW.domain.com/picture/subfolder/showpic/blah
    
    Code (markup):
    Whats the relevant syntax to put in my .htaccess file?

    Thanks
     
    THT, Oct 19, 2009 IP
  2. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #2
    The most easier way will be doing something like this


    .htaccess write this

    RewriteEngine On
    RewriteBase /
    ErrorDocument 404 /showpic.htm


    showpic.htm it's actually an php file? then you need to write this
    $search=trim($_SERVER["REQUEST_URI"]);
    this will get you the called url .. and you extract the picture name with an explode
    like $excade=explode(''picture/subfolder/showpic/',$search);

    echo $excade[1]; // this is your image name :D :)

    so $img yu got with $_GET['img'] you can set it to excade[1]
     
    redhits, Oct 19, 2009 IP
  3. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    chadsmith, Oct 19, 2009 IP
  4. THT

    THT Peon

    Messages:
    686
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This is what I actually did:
    
    RewriteRule ^pictures/([^/]*)/showpic/([^/]*)$ /pictures/$1/showpic.htm?img=$2.JPG
    
    Code (markup):
    But i would now actually like:
    
    RewriteRule ^pictures/([^/]*)/([^/]*)$ /pictures/$1/showpic.htm?img=$2.JPG
    
    Code (markup):
    However that throws a 500? Why is that?
     
    THT, Oct 20, 2009 IP
  5. redhits

    redhits Notable Member

    Messages:
    3,023
    Likes Received:
    277
    Best Answers:
    0
    Trophy Points:
    255
    #5
    THT also tried what i told you :)
     
    redhits, Oct 20, 2009 IP