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 8542623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:06:46+00:00 2026-06-11T12:06:46+00:00

I had hotlink protection working, so I thought, but not for when the referrer

  • 0

I had hotlink protection working, so I thought, but not for when the referrer is local.

IndexIgnore *
Options +FollowSymlinks
RewriteEngine on
RewriteOptions MaxRedirects=10

RewriteCond %{REQUEST_URI} ^/image_dir/
RewriteCond %{REQUEST_URI} \.(png|gif|jpe?g)$ [NC]
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?domain.com/
RewriteRule ^(.*)$ /some_dir/some_file.php?querystring=$1 [L]

What I need is:

If the referrer is not from my site on any image request on the site, then redirect to the page with what image the user is requesting.

If the referrer is from my site and the request is for any image in the image_dir, then redirect, otherwise do not.

Any help is greatly appreciated!

EDIT: Here is the full file to help:

## Default .htaccess file
IndexIgnore *
Options +FollowSymlinks
RewriteEngine on
RewriteOptions MaxRedirects=10

# your rules were looping before, that's bad, this will stop it
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

# redirect the browser back to the referring page
RewriteCond %{REQUEST_URI} ^/img/
RewriteCond %{REQUEST_URI} \.(png|gif|jpe?g)$ [NC]
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?domain.com/
RewriteRule ^ %{HTTP_REFERER} [L,R]

# rewrite the request to the handler
RewriteCond %{REQUEST_URI} ^/img/
RewriteCond %{REQUEST_URI} \.(png|gif|jpe?g)$ [NC]
RewriteCond %{HTTP_REFERER} ^https?://(www\.)?domain.com/
RewriteRule ^(.*)$ /img/index.php?img_hash=$1 [L]


## Do pretty permalinks for our images
# these rules ensure you aren't clobbering legit requests (like to image.php) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# just in case, exclude the admin directory 
RewriteCond %{REQUEST_URI} !^/admin [NC] 

# rewrite 
RewriteRule ^(.*)$ /display_image.php?img_hash=$1 [L] 

Everything works exactly like I want except hotlinking:

domain.com/t4hd -> domain.com/display_image.php?img_hash=t4hd (WORKS)
domain.com/t4hd.jpg -> domain.com/display_image.php?img_hash=t4hd.jpg (WORKS)
domain.com/img/t4hd -> domain.com/img/index.php?img_hash=t4hd (WORKS)
domain.com/img/t4hd.jpg -> domain.com/img/index.php?img_hash=t4hd.jpg (WORKS)
domain.com/img/123/456/789/t4hd.jpg -> domain.com/img/index.php?img_hash=t4hd.jpg (DOES NOT WORK)

I still have to allow all requests to:

domain.com/admin/index.php (WORKS)
domain.com/profile/index.php (WORKS)

Hopefully this helps clarify what is going on. Apologies for not doing this in the beginning.

  • 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-11T12:06:47+00:00Added an answer on June 11, 2026 at 12:06 pm

    Try using these rules instead:

    # your rules were looping before, that's bad, this will stop it
    RewriteCond %{ENV:REDIRECT_STATUS} 200
    RewriteRule ^ - [L]
    
    # redirect the browser back to the referring page
    RewriteCond %{REQUEST_URI} ^/image_dir/
    RewriteCond %{REQUEST_URI} \.(png|gif|jpe?g)$ [NC]
    RewriteCond %{HTTP_REFERER} !^https?://(www\.)?domain.com/
    RewriteCond %{HTTP_REFERER} !^$
    RewriteRule ^ %{HTTP_REFERER} [L,R]
    
    # rewrite the request to the handler
    RewriteCond %{REQUEST_URI} ^/image_dir/
    RewriteCond %{REQUEST_URI} \.(png|gif|jpe?g)$ [NC]
    RewriteCond %{HTTP_REFERER} ^https?://(www\.)?domain.com/ [OR]
    RewriteCond %{HTTP_REFERER} ^$
    RewriteRule ^(.*)$ /some_dir/some_file.php?querystring=$1 [L]
    

    That is, I’m assuming this cryptic bit in your question:

    If the referrer is from my site and the request is for any image in the image_dir, then redirect, otherwise do not.

    means:

    “If the referer is from my site and the request is for any image in the image_dir, send the request to the some_file.php handler, otherwise don’t do anything.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Had this working well in Emacs 23.1.x but it appears to have broke in
Had to download Command Line Tools from Apple to get make to work, but
Had a good read through similar topics but I can't quite a) find one
Had received a module from CCAVENUE and it was working fine with Magento 1.6.2...
Had a page that was working fine. Only change I made was to add
Had a good search here but can't see anything that gets my mind in
Had this working; at one stage. The problem is the following text is now
I had a question in MySQL, did it correctly. But the book code differs
Had a search around and can't seem to find any options to do this,
Had a nice PHP/HTML/JS prototype working on my personal Linode, then tried to throw

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.