Reputation: 337
I'm trying to block direct access to the pages of my site. Only access from an iframe should be allowed. Example
iframe page -> /path/to/iframe.html
anyotherpage.html-> should be visible only from the iframe in iframe.html
Is there any way to achieve this with htaccess?
Upvotes: 1
Views: 4012
Reputation: 1922
You can try to check %{HTTP_REFERER}
:
RewriteCond %{HTTP_REFERER} your\.domain/iframe\.php
RewriteCond %{REQUEST_URI} ^/iframe.html
RewriteRule ^(.*)$ - [L]
RewriteCond %{HTTP_REFERER} !your\.domain/iframe\.php
RewriteCond %{REQUEST_URI} ^/iframe.html
RewriteRule ^(.*)$ /another_page [R,L]
In this rules iframe.php = page with iframe tag located. iframe.html = page which using as iframe
So, if you try to request iframe.html directly, you will get redirect to another page.
Upvotes: 2