user3141603
user3141603

Reputation:

Allow accessing a file only from specific URL in HTACCESS

I have no idea how to block entering to a specific file from every one except one website. I Have 2 websites, one with my website and other that I can upload to him any thing I want to. I want to allow image uploading to my website, but really it will upload the image to the other website, using AJAX. But I don't want people to be able to use the AJAX code for their sites too, I want that the other website will allow image uploading (AKA accessing to the PHP upload file) only from the first website.

I do not know how to use HTACCESS, I know only the basic, so here is an a example in PHP (and please help me to 'translate' it to HTACCESS):

<?php

     if($_SERVER[REQUEST_URI] == "/images/uploads/EXAMPLE" && $from != "http://www.example.com"){ // $from = from where the ajax request were sent.
          header("location: 403.html");
     }

?>

Upvotes: 1

Views: 7097

Answers (1)

ChaveVrey
ChaveVrey

Reputation: 320

You can give this a try, put the content below in your .htaccess file:

SetEnvIf Referer my-domain.com internal 
# 
<Files *> 
order Deny,Allow 
Deny from all 
Allow from env=internal 
</Files> 

Put the .htaccess file in website where you upload the image to. My-Domain.com is the domain that you would like to have access to the images.

Note: This is not tested

Upvotes: 4

Related Questions