Apache 仅允许通过iframe访问
我试图阻止直接访问我的网站页面。只允许从iframe进行访问。范例 iframe页面->/path/to/iframe.html anyotherpage.html->应仅在iframe.html中的iframe中可见Apache 仅允许通过iframe访问,apache,.htaccess,Apache,.htaccess,我试图阻止直接访问我的网站页面。只允许从iframe进行访问。范例 iframe页面->/path/to/iframe.html anyotherpage.html->应仅在iframe.html中的iframe中可见 有没有办法通过htaccess实现这一点 您可以尝试检查%{HTTP\u REFERER}: RewriteCond %{HTTP_REFERER} your\.domain/iframe\.php RewriteCond %{REQUEST_URI} ^/iframe.html
有没有办法通过htaccess实现这一点 您可以尝试检查
%{HTTP\u 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]
在此规则中,iframe.php=带有iframe标记的页面。
iframe.html=用作iframe的页面
因此,如果您试图直接请求iframe.html,您将被重定向到另一个页面。谢谢Sergio,代码可以正常工作。如果我想让它不仅适用于iframe.html,而且适用于除iframe.php之外的任何其他页面,该怎么办?可以在不必为每个目标html页面重复上述代码的情况下完成吗?例如,您可以将
RewriteCond%{REQUEST\u URI}^/iframe.html
替换为RewriteCond%{REQUEST\u URI}^/(.*).html
,这将适用于任何*.html