Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8148281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:37:03+00:00 2026-06-06T14:37:03+00:00

We’re currently using folders inside webroot to store images and videos which we’re loading

  • 0

We’re currently using folders inside webroot to store images and videos which we’re loading in views (using the usual html image helper) that require log in.

How can I prevent outside visitors from just doing a site.com/img/photos/1.jpg url and having access to the images?
From what I understand I can’t really use media views to render an image inside a proper view, and I can’t figure out if there’s a solution through htaccess manipulation.

Which is the best practise for this?
Perhaps choosing to go with a non-webroot folder would be best (although that would make it harder in the file-storing part)?

As poncha suggested, I tried editing the main .htaccess file into this

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{HTTP_REFERER} !localhost
   RewriteCond %{REQUEST_URI} ^app/webroot/img/
   RewriteRule .* / [L,F]
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L] 
</IfModule>

But the rewrite base line seems to be forbidding access to the whole site, and without it there seems to be no change in img access.

Edit 2:
Editing the htaccess inside webroot:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]

# this RewriteCond is needed to avoid rewrite loops
RewriteCond %{REQUEST_URI} !^/app/webroot/
RewriteRule (.*) app/webroot/$1 [L,R]


RewriteCond %{HTTP_REFERER} !127.0.0.1
RewriteCond %{REQUEST_URI} ^/app/webroot/img/
RewriteRule .* - [L,F]

</IfModule>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:37:04+00:00Added an answer on June 6, 2026 at 2:37 pm

    This checks if Referer http header is set to something containing your domain, and denies access to img/ folder if not.

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_REFERER} !site.com
    RewriteCond %{REQUEST_URI} ^img/
    RewriteRule .* / [L,F]
    

    Note: it is easy enough to “break” this protection if someone wants to steal your content, however, it does prevent hotlinking without the need to produce some sort of script that would pass thorugh all the images/videos to check if access should be granted.

    EDIT:

    In case your website is not in /, You have two options:

    1. Change RewriteBase to reflect the base uri of the site (eg RewriteBase /app/webroot/)

    2. Change RewriteCond to reflect the path from / (eg RewriteCond ^app/webroot/img/)

    The second option is preferred in your case because you have other rules there

    EDIT2:

    In your case, the whole set should look like this:

    RewriteEngine on
    RewriteBase /
    
    # this RewriteCond is needed to avoid rewrite loops
    RewriteCond %{REQUEST_URI} !^/app/webroot/
    RewriteRule (.*) app/webroot/$1 [L,R]
    
    RewriteCond %{HTTP_REFERER} !localhost
    RewriteCond %{REQUEST_URI} ^/app/webroot/img/
    RewriteRule .* - [L,F]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.