【发布时间】: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}&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