SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict bimalpoudel's Avatar
    Join Date
    Feb 2009
    Location
    Kathmandu, Nepal
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess MIME types

    I have a folder (photos) with .jpg files without the extension.
    For example, " 20100914165406970 " is a name of a unique file inside /photos.

    How should I make it force as jpg image file?
    Is it possible to do with .htaccess?
    Adding or forcing image/jpeg mime to such files?

    For example, if someone views http://server/photos/20100914165406970, it should serve the image (it is a real file being accessed). It should not show the download-popup window.
    It should behave as if I am browsing http://server/photos/20100914165406970.jpg

    Any .htaccess tricks to put inside /photos/.htaccess?
    Bimal Poudel @ Sanjaal Framework over Smarty Template Engine
    ASKING INTERESTING QUESTIONS ON SITEPOINT FOURM

    Hire for coding support - PHP/MySQL

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    bimal,

    The easiest way is to instruct Apache to serve the extensionless files IN THE photos DIRECTORY AS JPG IMAGES. Because I always have a problem getting my head around the AddType directive when NO file extension is used, though, I'd redirect extensionless files to the .jpg version with:
    Code:
    # .htaccess in the photos subdirectory
    
    RewriteEngine on
    RewriteRule ^([0-9]{17})$ $1.jpg [L]
    Of course, that REQUIRES the seventeen digits shown in your example so you may have to change the number of digits specified to suit your requirements.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •