Exclude images in protected folder?

Discussion in 'Setting-up protection' started by henrikpalmgren, Oct 23, 2010.

  1. henrikpalmgren

    henrikpalmgren aMember Pro Customer

    Joined:
    Jan 13, 2009
    Messages:
    7
    Hi. I've protected a folder: http://www.mysite.com/secure

    I have a php script for uploading images and audio files to my protected folder and subdirectories. I would like those images to be visible and accessible on an index page in the root of my site (http://www.mysite.com) for all visitors to see, including those who have not yet logged in/signed up.

    Is there any way I can exclude images from being protected, although they are in a protected folder?

    If so, how do I do this? What file do I need to edit?

    I've been searching the forum and I've found no clue on how to do this. Any help would be fantastic!
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    You can do this in .htaccess if you will add rewrite rule for each file that should not be protected.
    Create separate folder for images and files that should not be protected and upload these files and images to new folder. This will be more easy.
  3. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Can you give an example rule for a .gif image?

    David
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Here is example. If you have image test.jpg inside protected area and what to remove protection for this image change protection code in .htaccess this way:
    Code:
    ########### AMEMBER START #####################
    Options +FollowSymLinks
    RewriteEngine On
    
    ## allow access for any active subscription
    RewriteCond %{HTTP_COOKIE} amember_nr=([a-zA-Z0-9]+)
    RewriteCond /home/alexander/htdocs/PRO-3_0/data/new_rewrite/%1 -f.
    RewriteRule ^(.*)$ - [L]
    
    #### Rules that should be added
    RewriteCond %{REQUEST_URI} test.jpg$
    RewriteRule ^(.*)$ - [L]
    ####
    ## if user is not authorized, redirect to login page
    # BrowserMatch "MSIE" force-no-vary
    RewriteCond %{QUERY_STRING} (.+)
    RewriteRule ^(.*)$ http://localhost/PRO-3_0/plugins/protect/new_rewrite/login.php?v=-any&url=%{REQUEST_URI}?%{QUERY_STRING} [L,R]
    RewriteRule ^(.*)$ http://localhost/PRO-3_0/plugins/protect/new_rewrite/login.php?v=-any&url=%{REQUEST_URI} [L,R]
    ########### AMEMBER FINISH ####################
    
  5. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    RewriteCond %{REQUEST_URI} test.jpg$

    This will exclude test.jpg.

    What can be used to exclude all jpg?

    David
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    RewriteCond %{REQUEST_URI} .jpg$
  7. henrikpalmgren

    henrikpalmgren aMember Pro Customer

    Joined:
    Jan 13, 2009
    Messages:
    7
    Many Thanks

    Many thanks for this help guys, it worked great!

Share This Page