IIS文档根在子文件夹中 [英] IIS document root in subfolder

查看:107
本文介绍了IIS文档根在子文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有一个PHP Windows Azure项目,但是我是IIS的新手.我的PHP库位于根文件夹中,而客户端文件(如index.php,样式表或javascripts)位于一个名为document_root的子文件夹中.

Hey, I have a PHP Windows Azure project but I am new to IIS. I have my PHP libs in root folder and client files like index.php, style sheets or javascripts in a subfolder called document_root.

如何设置IIS 7(可能使用Web.config)以将document_root用作站点的默认文件夹(使根目录不可见),以便我可以调用mydomain.tld/而不是mydomain.tld/document_root/

How can I set up IIS 7 (probably using Web.config) to use the document_root as the default folder for the site (making the root invisible) so i can call mydomain.tld/ instead of 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)

Which works fine but it accesses only the index.php and cant find any files like /document_root/css/default.css (the relative address is css/default.css)

推荐答案

有两种方法可以做到这一点.简单的方法是使用IIS7中包含的URL重写模块.将请求重定向到公共"文件夹(并禁止直接访问该文件夹)的示例:

There are 2 ways to do this. The easy route is to use the URL Rewriting module included in IIS7. An example to redirect requests to the Public folder (and disallow direct access to that folder) :

<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设置.为此,您需要重写Web角色的OnStart方法,但我认为第一个解决方案将满足您的需求.

The other way is to change the IIS settings once your PHP application is deployed. To do that you need to override the OnStart method of your web role, but I think the first solution will suit your needs.

这篇关于IIS文档根在子文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆