.htaccess 禁止直接访问htm文件,允许通过标记访问< frame>

1l5u6lss  于 2023-01-26  发布在  其他
关注(0)|答案(1)|浏览(107)

我正在使用一个旧的Web应用程序,它使用HTML4 <frame>标签在index.php文件中插入导航栏、内容等。
我想允许<frame>标记加载这些文件,但要阻止直接访问这些.htm文件。
不可能改变这些.htm文件中的任何一个,因为它们是在下次应用程序更新输入时自动构建的,所以我想必须通过.htaccess来完成。
我尝试过使用下面的代码,但是这会阻止.htm文件加载到<frame>标记中:

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^https://(www\.)?domain [NC] 
RewriteCond %{HTTP_REFERER} !^https://(www\.)?domain.*$ [NC] 
RewriteRule \.(htm)$ - [F]

框架标记部分:

<frameset>
   <frame src="index.htm">
</frameset>
vjrehmav

vjrehmav1#

已重写条件以检查引用(index.php)。

RewriteCond %{HTTP_REFERER} !^https://example.com/index.php$ [NC] 
RewriteRule \.(htm)$ - [F]

感谢CBroe让我头脑清醒。

相关问题