【发布时间】:2019-02-17 19:16:51
【问题描述】:
我正在尝试将我的所有子域托管在我的网络服务器上的相应文件夹中
https://foo.bar.com/index.html
位于
https://bar.com/foo/index.html
但是,根据我当前的配置,该文件不能也不应该通过“原始”链接访问。
我目前的方法有效,除了 urls,它指向路径中没有文件名的子目录 - 在这种情况下,子域被重新包含在 rewritten 网址:
https://foo.bar.com/this/does/work.html
提供位于
的文件https://bar.com/foo/this/does/work.html
同时
https://foo.bar.com/this/does/not/work
在浏览器中被重写为
https://foo.bar.com/foo/this/does/not/work
由于显而易见的原因导致 404。
如果您在浏览器中直接输入有问题的网址
https://foo.bar.com/this/does/not/work
它按预期工作。
我知道我在使用“显然”这个词的含义很宽松。这是一个快速演示:
你应该在那里看到,页面上的链接 https://egal.todoservice.app/sub/dir/
带你去 https://egal.todoservice.app/egal/sub/dir/
但尝试直接在地址栏中输入该链接,它可以工作 - 至少对我有用,在 Chrome、Edge 和 Firefox 中进行了测试。
更新:奇怪的是,在 stackoverflow 上使用 subdir 链接可以按预期工作......
这是我的 web.config 中负责子域重写的部分
<rule name="Rewrite Subdomain To Directory" stopProcessing="false">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.+)\.todoservice\.app$" />
</conditions>
<action type="Rewrite" url="{C:1}/{R:0}" />
</rule>
这是我的完整 web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="text/plain" />
<mimeMap fileExtension=".nupkg" mimeType="application/zip" />
</staticContent>
<rewrite>
<rules>
<rule name="Rewrite SMZC URL" stopProcessing="false">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.sadmenszombieclub.com" />
</conditions>
<action type="Rewrite" url="smzc/{R:0}" />
</rule>
<rule name="Rewrite imagiro URL" stopProcessing="false">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.imagiro.net" />
</conditions>
<action type="Rewrite" url="imagiro/{R:0}" />
</rule>
<rule name="Rewrite Subdomain To Directory" stopProcessing="false">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(.+)\.todoservice\.app$" />
</conditions>
<action type="Rewrite" url="{C:1}/{R:0}" />
</rule>
<rule name="Rewrite root path to service Directory" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^todoservice\.app$" />
</conditions>
<action type="Rewrite" url="service/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
整个网站作为 Azure Web 应用托管。
【问题讨论】:
-
<action type="Rewrite" url="{C:1}/{R:0}" />应该包含完整的域名(并且您还需要启用 ARR 代理模式,tomssl.com/2015/06/15/…)。 -
我想我明白你在说什么 - “真正的”域名(即 blabla.azurewebsites.com)应该在那里,并且只适用于安装的 ARR ......但你能启发我为什么在给出请求的文件时我的方法有效?
-
我正在尝试做与那篇文章中描述的完全相反的事情 - 将来自那个域“foobar.azurewebsites.com”的内容提供给不同的域和子域......我只是可以'不要把我的头绕在这上面。
-
@LexLi 我让它工作了。谢谢你。如果您将评论变成答案,我将很乐意接受。
标签: iis url-rewriting web-config azure-web-app-service