Mobile app version of vmapp.org
Login or Join
Berryessa370

: Can I allow access to a HTML page only if the user comes from a specific site with .htaccess? A website with two HTML pages, A and B. Both can be accessed by typing the URL, of course.

@Berryessa370

Posted in: #Htaccess #Referrer

A website with two HTML pages, A and B.

Both can be accessed by typing the URL, of course.

However, can I disallow any access to page B, and only allow it if the user is coming from page A? As in, a link in page A that redirects to page B.

Is it possible with .htaccess, or are there other alternatives?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Berryessa370

1 Comments

Sorted by latest first Latest Oldest Best

 

@Frith620

Yes. In the example below, people reaching page B from a page other than A will receive a forbidden error. To do it, you need something like this:

RewriteCond %{HTTP_REFERER} !^http://www.yoursite.com/A.html$
RewriteRule B.html - [F,NC]


Substitute yoursite and the html extension as appropriate for your case.

Note that this is not a secure way of doing this as people can spoof the referrer. If you want a secure way of doing this, you will need a login over SSL instead of using the referrer.

As one commenter noted, sometimes legitimate users do not show a referrer field or an incorrect one. Sometimes privacy software do this but it breaks a things (like hotlink protection) on many sites, so it is not that common anymore.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme