保护服务器上的XML文件器上、文件、XML

2023-09-02 09:52:06 作者:泛黄的情书

我在这里读到很多关于保护的文件的Apache服务器上的答案,有的说htaccess只​​是针对拒绝对文件的用户访问。对我来说不是。

I read here lot of answers about protecting a file on apache server, some told htaccess is only for deny user access for files. For me not..

使用以下几行,我不能达到的XML,但我的PHP脚本也不能!

Using the following lines I cant reach the xml, BUT my php script also can't!

<Files sample.xml>
  Order allow,deny
  Deny from all
</Files>

因此​​,如何保护用户的文件,使我的php脚本可以访问它。该文件是在根目录。

So how to protect a file from users, so that my php script could access it. The file is in the root dir.

推荐答案

如果你是一个Linux服务器上,有一个shell访问它,你改变你的文件权限

If you are on a linux server, have a shell access to it, you change your file permissions to

chmod 0700 yourxmlfile.xml  # this will make it readable/writable/executable only by the creator of the file.

或你的.htaccess文件,你可以这样做:

or in your .htaccess file, you can do this:

RewriteEngine on
RewriteRule ^yourfile.xml$ 404.html

在您404.html可以是一个找不到页或任何的垃圾页面,该页面将显示为无效链接。

where your 404.html could be either a page not found page or any garbage page, which will display as invalid url.