ASP.net URL重写力小写 [英] ASP.net url rewrite force lowercase

查看:261
本文介绍了ASP.net URL重写力小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

 <! - 力小写URLS  - >
<重写URL =〜/(* [A-Z] +。*)$为=〜/处理器/ permredirect.ashx URL = $ {较低($ 1)}?/>

烫发只需重定向301重定向到新的URL。

这条规则是为了任何URL重定向以大写字符为小写的。

然而,这将创建一个重定向循环,任何想法,为什么?到目前为止运行的唯一规则是:

 <&着意GT;    <! - 对所有网址中删除尾随斜线 - >
    <重写URL =?〜/(.*)/($ | \\(。*)),以=?〜/处理器/ permredirect.ashx URL = $ {较低($ 1)} $ 2/>    <! - 力小写 - >
    <重写URL =〜/(* [A-Z] +。*)$为=〜/处理器/ permredirect.ashx URL = $ {较低($ 1)}?/>    <重写URL =〜/ construct2($ ​​| \\(*)?)为=〜/ construct2.aspx处理=停止/>
< /重写>


解决方案

您可以修改常​​规的前pression排除.ashx的文件(这可能会变得非常复杂)或创建此规则之前一个新的规则,即将捕获的URL指向ASHX文件,并将其重定向到字符串的小写版本。

像这样的东西可能会奏效(未测试):

 <(?。=(* \\ ASHX *))〜/(。* [AZ] + *)重写URL =来=〜/ $ {较低($ 1)}/>

它使用一个超前的规则,以检查是否ashx的是URL的一部分,如果该URL是大写的。如果是的话,它重定向到相同的URL的小写版本。

I have:

<!-- Force lowercase URLS -->
<rewrite url="~/(.*[A-Z]+.*)$" to="~/handlers/permredirect.ashx?URL=${lower($1)}" />

Perm redirect simply 301 redirects to the new URL.

This rule is meant to redirect any URL with an uppercase char to the lower case one.

This however creates a redirect loop, any ideas why? The only rules running so far are:

<rewriter>

    <!-- Remove Trailing Slash for all URLS-->
    <rewrite url="~/(.*)/($|\?(.*))" to="~/handlers/permredirect.ashx?URL=${lower($1)}$2" />

    <!-- Force lowercase-->
    <rewrite url="~/(.*[A-Z]+.*)$" to="~/handlers/permredirect.ashx?URL=${lower($1)}" />

    <rewrite url="~/construct2($|\?(.*))" to="~/construct2.aspx" processing="stop" />
</rewriter>

解决方案

You can either modify the regular expression to exclude .ashx files (which might get extremely complicated) or create a new rule before this rule, that will catch URLs pointing to ashx files and redirect them to a lowercase version of the string.

Something like this might work (not tested):

<rewrite url="~/(?=(.*\.ashx.*))(.*[A-Z]+.*)" to="~/${lower($1)}" />

It uses a lookahead rule to check if ".ashx" is part of the url and if the URL is uppercase. If yes, it redirects to the lowercase version of the same url.

这篇关于ASP.net URL重写力小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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