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

发布于 2024-11-03 15:11:08 字数 533 浏览 4 评论 0原文

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

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.

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/

I have used:

<defaultDocument>
  <files>
    <clear />
    <add value="document_root/index.php" />
  </files>
</defaultDocument>

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风蛊 2024-11-10 15:11:08

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

<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 方法,但我认为第一个解决方案将满足您的需求。

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>

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.

变身佩奇 2024-11-10 15:11:08

修改基本设置和网站绑定。如果您只有一个网站,您可能只想编辑默认网站的基本设置:

  1. 打开 IIS 管理器
  2. 单击“操作”下的“默认网站”
  3. (右侧),选择“基本设置”
  4. “编辑物理位置”。

如果您在一台开发计算机上测试多个网站(具有不同的“DOCUMENT_ROOT”文件夹),请右键单击列表中的每个网站,编辑绑定,然后将各个网站设置为在不同的端口号下运行。然后,您可以使用(例如)访问各个网站:http-colon-slash-slash localhost:81

Modify the BASIC SETTINGS and WEBSITE BINDINGS. If you only have one website, you will probably just want to edit the BASIC SETTINCGS for the DEFAULT WEBSITE:

  1. Open IIS Manager
  2. Click on Default Web Site
  3. Under Actions (right hand side), select Basic Settings
  4. Edit Physical Location.

If you are testing several websites on one development machine (with different "DOCUMENT_ROOT" folders), right-click on each website in the list, Edit Bindings, and set the various websites to run under different Port Numbers. Then, you can access the various websites using (for example): http-colon-slash-slash localhost:81

愿与i 2024-11-10 15:11:08

我是从另一个角度来看待这个问题的(对 PHP 知之甚少,但对 IIS 和 Azure 很了解)。我不知道为什么你的项目是这样构建的,所以我只是假设它由于某种原因必须是这样的。我想指出的是,根据我的经验,将一个子文件夹作为根目录而不只是将其放在根目录中有点不典型。

无论如何,我将研究的技术称为重写或路由,它可以让您改变 URL 解析和传递到执行页面的标准方式。 Stackoverflow 有很多关于它的帖子,您可能想浏览一下,这里有一篇不错的 IIS URL重写与 URL 路由 给出了两种不同类型的路由以及在何处使用哪种路由的答案。

你可以在 web.config 中完成它,它应该可以让你实现你想要的。

I am coming at this from the other angle (knowing little PHP but IIS and Azure well). I don't know why your project is structured the way it is, so I'll just assume it has to be that way for some reason. I would just like to point out that in my experience it's a little atypical to have a subfolder that you want to work as the root and not just have it at the root.

Regardless, the techniques I would look at are called Rewriting or Routing, which lets you change from standard the way that URLs are parsed and passed to executing pages. Stackoverflow has lots of posts about it that you might like to trawl, here's a good one IIS URL Rewriting vs URL Routing which gives an answer as to two different types of routing and where to use which.

You can do it in web.config, and it should let you achieve what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文