我们使用来自http://urlrewriting.net的 DLL和类似于以下的规则:
<urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<add name="Customer" virtualUrl="^~/([^/]+)/([^/]+).aspx" destinationUrl="~/$2.aspx?customer=$1"/>
<add name="CustomerStart" virtualUrl="^~/([^/]+)/$" destinationUrl="~/Default.aspx?customer=$1"/>
<add name="CustomerStartAddSlash" virtualUrl="^http\://([^/]+)/([a-zA-Z0-9_-]+)$"
destinationUrl="http://www.example.com/$2/"
redirect="Domain" redirectMode="Permanent" />
</rewrites>
</urlrewritingnet>
这些规则执行以下映射。这些是rewrites,所以用户总是在他的浏览器中看到左边的 URL:
Rule 1: http://www.example.com/customerA/something.aspx => http://www.example.com/something.aspx?customer=customerA
Rule 2: http://www.example.com/customerA/ => http://www.example.com/Default.aspx?customer=customerA
第三条规则是重定向而不是重写,即,它确保在用户的浏览器中添加尾部斜杠(确保相对路径正常工作):
Rule 3: http://www.example.com/customerA => http://www.example.com/customerA/