Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 仅允许通过iframe访问_Apache_.htaccess - Fatal编程技术网

Apache 仅允许通过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

我试图阻止直接访问我的网站页面。只允许从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
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