嘿,我有一个 PHP Windows Azure 项目,但我是 IIS 新手。我的 PHP 库位于根文件夹中,而客户端文件(例如 index.php、样式表或 javascript)位于名为 document_root 的子文件夹中。
如何设置 IIS 7(可能使用 Web.config)以使用 document_root 作为站点的默认文件夹(使根目录不可见),以便我可以调用 mydomain.tld/而不是 mydomain.tld/document_root/
我用过:
<defaultDocument>
<files>
<clear />
<add value="document_root/index.php" />
</files>
</defaultDocument>
效果很好,但它只访问index.php,找不到任何像/document_root/css/default.css这样的文件(相对地址是css/default.css)
最佳答案
有两种方法可以做到这一点。最简单的方法是使用 IIS7 中包含的 URL 重写模块。将请求重定向到公共(public)文件夹(并禁止直接访问该文件夹)的示例:
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="blockAccessToPublic" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="/public/*" />
</conditions>
<action type="CustomResponse" statusCode="403" statusReason="Forbidden: Access is denied." statusDescription="You do not have permission to view this directory or page using the credentials that you supplied." />
</rule>
<rule name="RewriteRequestsToPublic" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
</conditions>
<action type="Rewrite" url="public/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
另一种方法是在部署 PHP 应用程序后更改 IIS 设置。为此,您需要重写网络角色的 OnStart 方法,但我认为第一个解决方案将满足您的需求。
关于php - 子文件夹中的 IIS 文档根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5796085/