[.htaccess question] How to make .jpg -> .png

Discussion in 'Apache' started by inaga, Jul 31, 2008.

  1. #1
    I want to make soccer.jpg accessible from soccer.png even though only soccer.jpg excists on the server.

    how do i do this :)?
     
    inaga, Jul 31, 2008 IP
  2. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #2
    Try this:

    
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^soccer.png$ /soccer.jpg [L]
    
    Code (markup):
    If your .jpg is located in some subfolder, then you will need to include that in the rule also, something like this:

    
    RewriteRule ^subfolder/soccer.png$ /subfolder/soccer.jpg [L]
    
    Code (markup):
     
    pr0t0n, Aug 1, 2008 IP
  3. RectangleMan

    RectangleMan Notable Member

    Messages:
    2,825
    Likes Received:
    132
    Best Answers:
    0
    Trophy Points:
    210
    #3
    I think you will also need to change the type. Look into AddType for apache. This will allow a jpg to be served as a png.
     
    RectangleMan, Aug 1, 2008 IP
  4. inaga

    inaga Active Member

    Messages:
    949
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Sorry I didn't explain myself clearly enough. I didn't mean for just 1 file (i was just giving an example), I want all the files in the directory that are jpg to be served as png

    i tried looking into this before but it didn't seem to work out :/ can u maybe give me the exact code.
     
    inaga, Aug 1, 2008 IP
  5. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #5
    RewriteRule ^subfolder/(.*)\.png$ /subfolder/$1.jpg [L]
     
    Scorpiono, Aug 1, 2008 IP
  6. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Scorpiono, what have I taught you? (.*) is greedy:

    RewriteRule ^subfolder/(.*?)\.png$ /subfolder/$1.jpg [L]
    Code (markup):
    ;)
     
    jayshah, Aug 2, 2008 IP
  7. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #7
    Awww... greedy greedy ya! *shy*
     
    Scorpiono, Aug 3, 2008 IP
  8. inaga

    inaga Active Member

    Messages:
    949
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    60
    #8
    how is it greedy? what's the difference? and thanks it works :).
     
    inaga, Aug 3, 2008 IP
  9. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #9
    (.*) will match *everything*
    (.*?) will match just what it needs :)

    Jay
     
    jayshah, Aug 3, 2008 IP
  10. Scorpiono

    Scorpiono Well-Known Member

    Messages:
    1,330
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    120
    #10
    abcdabc

    greedy ab will match ab
    non-greedy ab will match abcdab
     
    Scorpiono, Aug 11, 2008 IP
  11. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #11
    jayshah, Aug 11, 2008 IP