homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Displaying a .gif instead of a .jpg
using .htaccess

 10:47 am on Sep 14, 2010 (gmt 0)

Hi guys,

I am trying to display a .gif instead of a .jpg using htaccess. I have added the following to both the root folder and my images folder but it doesn't seem to work:

RewriteCond %{REQUEST_FILENAME} ^foo.jpg
RewriteRule ^images/foo.jpg$ /images/foo.gif [L]

Any help greatly appreciated.



 10:58 am on Sep 14, 2010 (gmt 0)

surely the client browser still thinks it's a jpg? and thus won't render it anyway


 11:10 am on Sep 14, 2010 (gmt 0)

@topr8 probably the reason why then. Interestingly enough a 301 redirect seems to have done the trick. Thanks.


 11:28 am on Sep 14, 2010 (gmt 0)

A 301 redirect tells the browser to fetch a new URL.

That new URL will include the correct extension.

An internal rewrite cannot do that; imagine asking for an HTML page and having an Excel spreadsheet file returned for that
/filename.html URL request.

 12:15 pm on Sep 14, 2010 (gmt 0)

@g1smd - thanks for the clarification, guess I need to read up on Apache config ;)


 10:59 pm on Sep 14, 2010 (gmt 0)

Assuming that you also have the Options and RewriteEngine directives required to enable mod_rewrite, the only problem with that code in the unnecessary RewriteCond, that is in fact interfering with its function...


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved