如何使用 .htaccess 允许在我的 iframe 中访问页面而不是直接访问? [英] How to use .htaccess to allow page access in my iframe but not directly?

查看:20
本文介绍了如何使用 .htaccess 允许在我的 iframe 中访问页面而不是直接访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 iframe 制作的网站.我想在自己的 iframe 中显示一个页面,但我想拒绝直接访问.我如何在我的 .htaccess 中以这种方式保护它?

I have a site made with iframes. I have a page I want to show in my own iframes, but I want to deny direct access. How can I protect it that way in my .htaccess?

推荐答案

您可以使用 Referer HTTP 标头来检查请求是否来自您网站上的链接(或 img src/或 iframe src就此而言):

You can use Referer HTTP header to check if a request came from a link on your website (or img src / or iframe src for that matter):

RewriteEngine On
RewriteCond %{HTTP_REFERER} !example.com
RewriteCond %{REQUEST_URI} ^/path/to/protected/page$
RewriteRule . - [F]

其中example.com 是您的域名,/path/to/protected/page 是您要保护的路径

Where example.com is your domain name, and /path/to/protected/page is the paht you want to protect

但是,请注意,这种方法可能会被愚弄,因为远程用户可以构造 HTTP 标头(将 http 标头视为用户输入 - 不要相信它们;))

However, note that this approach can be fooled, as HTTP headers can be constructed by remote user (treat http headers as user input - do not trust them ;) )

这篇关于如何使用 .htaccess 允许在我的 iframe 中访问页面而不是直接访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆