0

您好,我对配置了解不多.htaccess,但我想限制对我的 Web 服务器上的 php 文件的访问,并且我只想index.php访问参数。

我的文件位于子文件夹中,例如:www.mydomain.com/sub/index.php. index.php我希望能够在子文件夹、css 文件和 js 文件中打开它。

这是我到目前为止的配置:

  Order Deny,Allow
  Deny from all
  Allow from 127.0.0.1

  <Files /index.php>
    Order Allow,Deny
    Allow from all
  </Files>
  <FilesMatch "*\.(css|js)$">
    Order Allow,Deny
    Allow from all
  </FilesMatch>

我试图做类似的事情,<Files sub/index.php>但每次它限制子文件夹中的所有 php 文件并且www.mydomain.com/index.php工作正常。

有人可以帮我吗?

4

2 回答 2

1

您可以将除需要通过 http(index.php、css、图像等)访问的文件之外的所有文件从 DocumentRoot 目录移出到上层,因此目录布局如下所示:

/lib
/files
/html
   /index.php
   /css/
   /images/

其中 /html 是您的 DocumentRoot。

在这种情况下,您将不需要 .htaccess 或 VirtualHost 配置中的任何其他限制性规则/

于 2012-11-03T21:20:31.597 回答
-1

htaccess 可能不是阻止直接访问某些 PHP 文件的最佳选择。相反,创建一个访问值并将其设置为您希望定向访问的页面中的某个值,否则不要在其他页面中设置它。

$access = 'some value';
if(empty($access)) { header("location:index.php"); die();}

这样其他 php 文件只能通过 include 或 require 访问。希望有帮助。

于 2012-11-03T21:15:52.953 回答