如何在 Apache 中只允许一个文件

发布于 2024-12-09 20:46:28 字数 338 浏览 1 评论 0原文

我有一个名为 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 .htaccessand 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半衬遮猫 2024-12-16 20:46:29

我所做的只是将所有请求重定向到 index.php 文件,并让索引文件处理任何错误请求,因为它已经处理了所有友好的 URL 请求和所有内容。这样您就不需要在索引文件中添加额外的代码。它将正常运行并看到“somefile.php”和他们试图打开的页面,并确定这不是要打开的有效页面,并像任何其他无效路径一样出错,至少对于我的方式来说是这样设置。

RewriteEngine On
RewriteBase /
RewriteRule .* index.php [L]

如果您不像我一样使用子域,则必须排除任何图像或 CSS 文件夹,或者您也可以使用索引文件处理它们。

排除图像和 css 文件夹的示例:

RewriteRule !^(images|css)/.* index.php [L]

或者如果您不想这样做,您可以将所有不允许的文件发送到 -

RewriteRule !^(index\.php|images/.*|css/.*) - [L]

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.

RewriteEngine On
RewriteBase /
RewriteRule .* index.php [L]

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:

RewriteRule !^(images|css)/.* index.php [L]

Or if you don't want to do that, you could send all the disallowed files to -.

RewriteRule !^(index\.php|images/.*|css/.*) - [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文