Question

Include attempted solutions, why they didn't work, and the expected results.

Hi there. I want to make a certain page on my website eg. site.com/content/B.html accessible only if you click the link that points to site.com/content/B.php from a specific page on the site eg. site.com/A.html

What I have tried to do so far is putting this code in a .htaccess file inside site.com/content:

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

This was supposed to return a 403 error only if you tried to open site.com/content/B.php using a link from some other site or just typing site.com/content/B.php into the address bar of the browser, but instead it returns a 403 error when opening it from site.com/A.html as well.

I expected for it to return a 403 error if opened from a different location, and for it to display B.php if opened from A.html

I hope that you follow and I would really appreciate some advice. Thank you in advance.

Was it helpful?

Solution

Can you try this rule:

RewriteCond %{HTTP_REFERER} !^http://(www\.)?site\.com/ [NC]
RewriteRule (^|/)B\.php(/|$) - [F,NC]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top