Search code examples
apachesecurity.htaccessserver-side

how to make sure that web traffic originates ONLY via a specific URL?


I have a site (A) that I would like to distribute to students. I have some materials there that I do not want to make public, as the materials will serve as a future textbook that I would like to sell.

Is there any way to make sure that access is only granted if the user navigates to site (A) via another site (B)??

For example, site (A)

somesite.com/page_to_be_exposed.html

Will only be viewable if navigated to from site (B):

anothersite.com/somepage.html

I am open to any suggestions, but I figured a solution might have something to do with the tags I've posted here. I'll add other tags if people find a need for other methods / languages.

Thanks for any suggestions, this is all very new to me. jml


Solution

  • You can use a .htaccess file as you have found it can have to do with this.

    Having mod_rewrite enabled a rule like:

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://example.com
    RewriteRule - - [R=403,L]
    

    In a .htaccess file located in the root of the directory you want to protect against hot-linking, should do the job.

    However this will only avoid people from hot-linking, not from accesing your content. So if security is a concern. Take a look at Apache’s mod_auth_basic .