#1
  1. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    619
    Rep Power
    17

    Redirect images to php page


    I have non existent images located at /poke/number.png
    What i want to do is redirect these requests to a page, poke.php?id=number
    where number is the number from the png image name

    example

    /poke/123.png becomes poke.php?id=123
    /poke/444.png becomes poke.php?id=444

    etc.

    I believe i need to use htaccess but don't know what i need to put
  2. #2
  3. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,972
    Rep Power
    9647
    It's a fairly straightforward concept so there's tons of information about how to do it on the internet.
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^poke/(\d+)\.png$ poke.php?id=$1 [L]
  4. #3
  5. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    619
    Rep Power
    17
    turns out i had it almost correct, was missing the RewriteEngine on line

    With that its not showing a 404 anymore but its not redirecting either, just get a blank white screen
  6. #4
  7. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,972
    Rep Power
    9647
    It won't redirect you as it is - it happens behind the scenes. If you're not sure that it's working then add a [R] flag to the RewriteRule.

    A blank white page sounds like a PHP problem. Looked into that?
  8. #5
  9. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    619
    Rep Power
    17
    Got it to work by changing
    RewriteRule ^poke/(\d+)\.png$ poke.php?id=$1
    to
    RewriteRule ^poke/(\d+)\.png$ /poke.php?id=$1

IMN logo majestic logo threadwatch logo seochat tools logo