【发布时间】:2019-07-16 20:31:47
【问题描述】:
我已经阅读了很多论坛,并且尽我所能。我的出站规则适用于为 SEO 目的重写 URL,但我的 Redict URL 以防万一我们用户书签中标记的更改 URL 不起作用。 我正在使用 IIS 10.0。
需要修改的网址:
http://agmodel.com/files/content/insights/publishing/e_clouds.pdf
到: http://agmodel.com/assets/content/insights/publishing/e_clouds.pdf
所以我唯一要更改的是将字符串“files”更改为“assets”。
这是我尝试过的:
尝试 1:
<rule name="Redirect" stopProcessing="true">
<match url="(https?:\/\/[^\/]+)\/" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="(https?:\/\/[^\/]+)\/files\/(.*)" />
<add input="{REQUEST_URI}" pattern="^/assets" negate="true" />
</conditions>
<action type="Redirect" url="{R:1}/assets/{C:2}" appendQueryString="false" redirectType="Found" />
</rule>
我试图确保第一个模式始终是域,第二个模式是文件。
尝试 2:
<rule name="assets-to-files" stopProcessing="true">
<match url="(https?:\/\/[^\/]+)\/files\/(.*)" />
<action type="Redirect" url="{R:1}/assets/{C:1}" appendQueryString="false" logRewrittenUrl="true" />
<conditions>
<add input="{QUERY_STRING}" pattern="\/files\/(.*)" />
</conditions>
</rule>
所以每当我测试添加书签的旧网址是否会更改为新网址时,它都不起作用。在 IIS 10 中的模式匹配测试期间,它会亮起绿灯。
我在这里做错了什么?
【问题讨论】:
-
你想将
files重定向到assets,所以,试试<rule name="assets-to-files"><match url="^files/(.*)" /><action type="Rewrite" url="assets/{R:1}" /></rule> -
blog.lextudio.com/… 中的错误 1
-
@WiktorStribiżew 成功了。谢谢!我以前没有使用 ^ 因为它在测试模式中不起作用,但它在真正的重定向中起作用。很奇怪为什么 ^ 在测试模式中不起作用。
-
@GerleBatde 太好了,我将其添加为答案。请考虑接受/支持。
标签: regex url-rewriting web-config url-redirection iis-10