禁止使用.htaccess EXCEPT for XMLHttpRequest访问php文件(文件夹)

编程入门 行业动态 更新时间:2024-10-27 06:18:42
本文介绍了禁止使用.htaccess EXCEPT for XMLHttpRequest访问php文件(文件夹)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个文件夹 www.mysite/page/panel/soascripts / ,其中有10个不同的PHP文件。 我想防止访问文件夹 soascripts 及其中的php文件。除了 X-Requested-With = XMLHttpRequest (用于ajax)。 htaccess有可能吗?

I have a folder www.mysite/page/panel/soascripts/ where there are 10 different PHP files. I want to prevent access to the folder soascripts and the php files in it. Except X-Requested-With = XMLHttpRequest (for ajax). Is this possible with htaccess?

推荐答案

在soascripts文件夹中的htaccess文件中:

In the htaccess file in your soascripts folder:

RewriteEngine On RewriteCond %{HTTP:X-Requested-With} !=XMLHttpRequest RewriteCond %{HTTP:X-REQUESTED-WITH} !^(XMLHttpRequest)$ RewriteRule \.php$ - [L,F]

所以没有

X-Requested-With: XMLHttpRequest

请求标头,响应将被禁止为403。

request header, the response will be a 403 forbidden.

编辑:

如果要将规则添加到文档根目录,则只需要包括以下路径:

If you want to add the rules to the document root, you just need to include the path:

RewriteCond %{HTTP:X-Requested-With} !=XMLHttpRequest RewriteCond %{HTTP:X-REQUESTED-WITH} !^(XMLHttpRequest)$ RewriteRule ^page/panel/soascripts/[^/.]+\.php$ - [L,F]

请确保在任何类型的路由规则之前( 之前添加它(例如将内容发送到 index.php )。

Make sure to add it before any type of routing rules (like stuff being sent to index.php).

更多推荐

禁止使用.htaccess EXCEPT for XMLHttpRequest访问php文件(文件夹)

本文发布于:2023-10-31 16:46:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546681.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   禁止使用   文件   XMLHttpRequest   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!