【问题标题】:IIS: web.config redirect to another url preserving the original one in the address barIIS:web.config 重定向到另一个 url,保留地址栏中的原始 URL
【发布时间】:2012-03-17 22:35:40
【问题描述】:

我正在尝试了解如何执行此操作,但似乎非常复杂(至少对于像我这样没有 IIS 经验但只有 Apache 的人来说)。我正在将一个网站从 Linux 移植到 Windows 服务器,在 linux 服务器上我有一个 .htaccess 可以帮助我重写 url 以隐藏页面和参数:

重写规则 ^store/([0-9a-zA-Z]+)$ http://www.domain.com/store/$1/ [R]

重写规则 ^store/([0-9a-zA-Z]+)/$ http://www.domain.com/pages/store.asp?name=$1

重写规则 ^store/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ http://www.domain.com/store/$1/$2/ [R]

重写规则 ^store/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/$ http://www.domain.com/pages/store.asp?name=$1&page=$2

所以当有人访问http://www.domain.com/store/client1/ 时访问http://www.domain.com/pages/store.asp?name=client1(等等最多有4 个参数),但在浏览器地址栏中显示的url 仍然是http://www.domain.com/store/client1/

我找不到在 IIS 7 上执行相同操作的方法...我做了如下的操作:

            <rule name="Rule 5">
                <match url="^store/([0-9a-zA-Z]+)$" ignoreCase="false" />
                <action type="Redirect" url="http://www.domain.com/store/{R:1}/" redirectType="Found" />
            </rule>
            <rule name="Rule 6">
                <match url="^store/([0-9a-zA-Z]+)/$" ignoreCase="false" />
                <action type="Redirect" url="http://www.domain.com/pages/store.asp?name={R:1}" appendQueryString="false" redirectType="Found" />
            </rule>
            <rule name="Rule 7">
                <match url="^store/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$" ignoreCase="false" />
                <action type="Redirect" url="http://www.domain.com/store/{R:1}/{R:2}/" redirectType="Found" />
            </rule>
            <rule name="Rule 8">
                <match url="^store/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/$" ignoreCase="false" />
                <action type="Redirect" url="http://www.domain.com/pages/store.asp?name={R:1}&amp;page={R:2}" appendQueryString="false" redirectType="Found" />
            </rule>

这适用于重定向,所以如果我调用 www.domain.com/store/arg1/arg2/ 我正在访问 www.domain.com/pages/store.asp?name={R:1}&page={ R:2} ,但在浏览器地址栏中我看到重定向地址 store.asp?name={R:1}&page={R:2} 而不是原来的 www.domain.com/store/arg1/arg2/ ,而是我需要的。

有没有办法做到这一点?我已经花了几个小时没有一个可行的解决方案......

【问题讨论】:

    标签: asp.net iis redirect asp-classic rewrite


    【解决方案1】:

    不要使用Redirect 类型的操作,而是使用Rewrite。有关更多信息,请参阅此blog post。这会将服务器上的 URL 重写为您想要的 URL,而不是将浏览器重定向到新的 URL。

    【讨论】:

      猜你喜欢
      • 2012-05-22
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      • 2017-05-09
      • 1970-01-01
      • 2012-12-04
      • 2021-04-15
      • 2015-07-27
      相关资源
      最近更新 更多