gpt4 book ai didi

regex - IIS-URL 重写,URL 规则为小写,除了查询字符串

转载 作者:行者123 更新时间:2023-12-01 09:54:57 24 4
gpt4 key购买 nike

您好我在 IIS 中使用 URL 重写模块。
我会创建一个规则来转换小写网址。但是,我有问题。
我的目标是做到以下几点:

http://www.doMain.com/App/ActIon?X=1&y=3&JJ=3... => http://www.domain.com/app/action?X=1&y=3&JJ=3...

我的第一次失败尝试是:
<rule name="LowerCaseRule1" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>

结果:
http://www.doMain.com/App/ActIon?X=1&y=3&JJ=3... => http://www.domain.com/App/ActIon?X=1&y=3&JJ=3...

它仅适用于域(因为 URL 变量只有域)

我第二次失败的尝试是:
<rule name="Convert to lower case" stopProcessing="true">  
<match url=".*[A-Z].*" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />
</rule>

结果:
http://www.doMain.com/App/ActIon?X=1&y=3&JJ=3... => http://www.domain.com/app/action?x=1&y=3&jj=3...

这也适用于查询字符串。所以我没有侍奉我。

我的第三次失败尝试是:
<rule name="Convert to lower case" stopProcessing="true">  
<match url="^(.*[A-Z].*)(\/.*)" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
</rule>

结果:
http://www.doMain.com/App/ActIon?X=1&y=3&JJ=3... => http://www.domain.com/app/ActIon?X=1&y=3&JJ=3...

这个问题不适用于最后一条路径。

这会导致以下我需要的规则没有得到满足:
http://www.doMain.com/App => http://www.domain.com/app

问题:

有什么规则可以让我做我需要做的事吗?

使用模块是否正确?

因为我有另一种选择是使用 ASP.NET 路由引擎(例如 https://github.com/schourode/canonicalize )

最佳答案

只需稍作修改:中断 ? 上的 URL将文件名部分与查询字符串分开。

<rule name="Convert to lower case" stopProcessing="true">  
<match url="^([^?]*[A-Z][^?]*)(\?.*)?" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
</rule>

如果你使用散列( # ),你可能也应该打破它们,因为你不想强制它们都小写。
<rule name="Convert to lower case" stopProcessing="true">  
<match url="^([^?#]*[A-Z][^?#]*)(\?.*)?(#.*)?" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{R:1}}{R:2}{R:3}" redirectType="Permanent" />
</rule>

关于regex - IIS-URL 重写,URL 规则为小写,除了查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30108919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com