Allow access only through iframe

2019-09-13 01:37发布

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?

1条回答
我只想做你的唯一
2楼-- · 2019-09-13 02:15

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.

查看更多
登录 后发表回答