0

我的 iis7.5 服务器上有一个文件(称为“log.html”),我希望我的 PHP 安装能够访问和写入,但我不希望任何人直接访问该文件,例如输入' http://computername/log.html '(我在局域网上)。

如何阻止用户访问它但允许 php 看到它?

使用下面建议的 web.config 文件时,我收到此错误: web.config 错误

4

2 回答 2

1

您可以使用 IIS URL 重写并创建请求阻止规则来阻止通过 HTTP 的访问:

例如:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="BlockLogFile" 
              patternSyntax="Wildcard" 
              stopProcessing="true">
          <match url="*" />
          <conditions>
            <add input="{URL}" pattern="/log.html" />
          </conditions>
          <action type="CustomResponse" 
                  statusCode="403" 
                  statusReason="Forbidden: Access is denied." 
                  statusDescription="This is sekret!" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
于 2012-06-19T01:24:36.103 回答
1

我想我可能已经回答了我自己的问题!我仍然需要对其进行更多测试,也许如果它不能完全工作,那么有人可以纠正我:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpProtocol>
            <customHeaders>
                <add name="cache-control" value="no-store, no-cache, must-revalidate, max-age=0" />
            </customHeaders>
        </httpProtocol>
        <staticContent>
            <clientCache cacheControlMode="DisableCache" />
        </staticContent>
        <security>
            <requestFiltering>
                <denyUrlSequences>
                    <add sequence="log.html" />
                </denyUrlSequences>
            </requestFiltering>
        </security> 
    </system.webServer>
</configuration>

缓存控制位防止浏览器缓存它返回的任何内容。

希望这对其他人有帮助!我对此还是很陌生,所以你也许可以解决这个问题。

于 2012-07-17T16:57:50.560 回答