php - 子文件夹中的 IIS 文档根目录

标签 php iis iis-7 web-config azure

嘿,我有一个 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/

相关文章:

php - 如何在数组中产生行空间

c# - 访问路径 wwwroot 被拒绝,即使我有权限

azure - 使用 Azure AD 身份验证保护的 WebAPI 无法在 IIS 上工作,但在使用 Visual Studio 的 IIS Express 上工作正常

iis - 如何跟踪应用程序请求路由添加的开销?

javascript - 当没有行与搜索输入匹配时,如何隐藏表的 <thead> 元素? - JavaScript

php - 当包含来自多个目录的相同 css 文件时如何处理 CSS 中的路径

azure - 如何在 Azure 中允许 URL 编码路径段

asp.net - 删除 ASP.NET/IIS 7 应用程序中特定路径的 HttpModule?

iis-7 - IIS7 中的经典 ASP 应用程序变量

php - 将表单输入与正则表达式进行比较