SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess to only allow images to display in directory

    Hi,

    I'm having problems getting this .htaccess file to work. I would like to put the following in the parent level directory of the images directory so that only images can be displayed and nothing else. What's happening is that none of the images in the directories will display. However, I only want the specified images to display and no other file format.

    Here's the code:

    Code:
    deny from all
    
    <Files ~ "^\w+\.(gif|jpe?g|png)$">
    order deny,allow
    allow from all
    </Files>
    Do you see anything wrong with the above code?

    Thanks,

    Greg

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

    Yes, I don't believe that <FILES> can accept a NOT modifier. It's easier to use mod_rewrite (if available) to ONLY serve your image files:
    Code:
    # .htaccess in your images directory
    RewriteEngine on
    RewriteCond &#37;{REQUEST_URI} ^\.(gif|jpe?g|png)$ [NC]
    RewriteRule .? - [F,L]
    That checks for the image extensions and, if not found, will send a FAIL code to the browser (for that request).

    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

  3. #3
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I will try that.

  4. #4
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could I set this in the web root's .htaccess file and then set a rewrite rule for each directory that I would like to only display images?

    Something like this?

    # limit upload images directory for members
    RewriteEngine on
    RewriteCond &#37;{REQUEST_URI} ^upload\/members\/.*\.(gif|jpe?g|png)$ [NC]
    RewriteRule .? - [F,L]

    # limit upload images directory for groups
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^upload\/groups\/.*\.(gif|jpe?g|png)$ [NC]
    RewriteRule .? - [F,L]

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,607
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    dev,

    Yes, but why two RewriteEngine on statements and the unnecessary escapting of /'s?

    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
  •