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
3 番目のルールは、書き換えではなくリダイレクトです。つまり、ユーザーのブラウザに末尾のスラッシュが追加されるようにします(相対パスが正しく機能するようにします)。
Rule 3: http://www.example.com/customerA => http://www.example.com/customerA/