【问题标题】:IIS Rewrite for number at end of domain after slashIIS 在斜杠后重写域末尾的数字
【发布时间】:2016-05-18 19:14:02
【问题描述】:

我在 ASP.NET 中有一个脚本处理程序 (.ashx),它接受一个整数的查询字符串参数 ID。我想进一步缩短网址,例如:

当前:

https://domain.com/Link.ashx?ID=225 或者 https://www.domain.com/Link.ashx?ID=225

到:

https://domain.com/225

我没有使用 MVC,我怀疑我可以通过 IIS URL 重写来做到这一点。任何人都可以帮助解决支持此操作所需的配置吗?

http://domain.com/225 会重定向到https://domain.com/Link.ashx?ID=225

【问题讨论】:

    标签: asp.net iis url-rewriting url-redirection


    【解决方案1】:

    这应该可以。

      <rule name="test">
            <match url="^[0-9]+$" />
            <action type="Rewrite" url="Link.ashx?ID={R:0}" />
        </rule>
    

    ^ = 开头 [0-9] = 任意数字 + = 重复 1 次或多次 $ = 以

    结尾

    【讨论】:

    • 谢谢,尽管其他形式的 URL 没有数字,但我必须小心,即如果传入的 URL 为 domain.com/Link.ashx?ID=225,那么它会被重定向,或者其他 URL如:domain.com/?foo=99883&foo2=883773&r=00992.
    • 不,这只会匹配数字。所以 /1 /123 /1234 将全部匹配,但 /1a /a1 /12345r /?foo=99883etc 或任何其他非数字将不匹配
    猜你喜欢
    • 2012-04-12
    • 2011-12-08
    • 1970-01-01
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    • 2014-09-12
    • 2011-07-02
    • 2016-11-21
    相关资源
    最近更新 更多