如何在ASP.NET中重写URL?

例如,将用户定位到http://www.website.com/users/smith而不是http://www.website.com/?user=smith

解决方案

可以尝试使用托管的Fusion Url重写器和反向代理:

http://urlrewriter.codeplex.com

重写的规则是:

# clean up old rules and forward to new URL
RewriteRule ^/?user=(.*)  /users/ [NC,R=301]

# rewrite the rule internally
RewriteRule ^/users/(.*)  /?user= [NC,L]

或者使用IIS重写模块:

Microsoft现在为IIS提供了一个官方的URL重写模块:http://www.iis.net/download/urlrewrite

它支持大多数类型的重写,包括设置服务器变量和通配符。

日期:2020-03-24 10:33:35 来源:oir作者:oir