如何在 Apache 中只允许一个文件
我有一个名为 index.php
的引导文件,我只允许其他人调用此页面。
我编写了下面的代码,但收到了内部 500 错误。我喜欢显示日志文件,但我不能,因为我在共享主机上运行它,但我知道它是 CGI 模式。
我将该代码放入 .htaccess
中并收到错误,并将其放入 php.ini
中但不起作用。
<File /index.php>
Allow from all
Require None
Satisfy Any
</File>
我做错了什么?
I have a bootstrap file which is index.php
and I only allow this page to be called by people not other ones.
I've come up with the code below and I received an Internal 500 error. I like to show the log files but I cannot since I am running this on the shared hosting but what I know is it is CGI mode.
I put that code in .htaccess
and received error and put it in php.ini
and didn't work.
<File /index.php>
Allow from all
Require None
Satisfy Any
</File>
What's I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我所做的只是将所有请求重定向到
index.php
文件,并让索引文件处理任何错误请求,因为它已经处理了所有友好的 URL 请求和所有内容。这样您就不需要在索引文件中添加额外的代码。它将正常运行并看到“somefile.php”和他们试图打开的页面,并确定这不是要打开的有效页面,并像任何其他无效路径一样出错,至少对于我的方式来说是这样设置。如果您不像我一样使用子域,则必须排除任何图像或 CSS 文件夹,或者您也可以使用索引文件处理它们。
排除图像和 css 文件夹的示例:
或者如果您不想这样做,您可以将所有不允许的文件发送到
-
。What I do is just redirect all requests to the
index.php
file and let the index file handle any bad requests, since it already handles all the friendly URL requests and everything. This way you don't really need extra code in the index file. It will run normally and see 'somefile.php' and the page they're trying to open and determine that this is not a valid page to be opening and error out like any other invalid path, at least it would for the way mine is set up.You would have to exclude any images or CSS folders if you don't use sub-domains for them like I do, or you can process them with the index file as well.
Example for excluding images and css folders:
Or if you don't want to do that, you could send all the disallowed files to
-
.