我正在为多租户门户实现自定义登录页面,其中每个客户端根据其存储的设置获取不同的登录页面。
为实现这一点,我使用IIS 7.5和URL重写模块
我的想法是捕获“http://portal.com/client1/”的请求,并将其重写为“http://portal.com/login.aspx?client=client1”。
我正在努力的是正则表达式匹配URL并提取“client1”位。
实施例:
“http://portal.com/pepsi”=“http://portal.com/login.aspx?client=pepsi”
“http://portal.com/fedex”=“http://portal.com/login.aspx?client=fedex”
“http://portal.com/northwind”=“http://portal.com/login.aspx?client=northwind”
“http://portal.com/microsoft/”=“http://portal.com/login.aspx?client=microsoft”
因此,如果请求的URL在第一个“/”之后包含单个单词,则应找到该匹配,并且是否存在尾随“/”的工作。
"http://portal.com/clients/home.aspx" would be ignored by the rule.
"http://portal.com/clients/catalog" would be ignored by the rule.
"http://portal.com/products.aspx" would be ignored by the rule.
答案 0 :(得分:1)
假设:
client
/client1/
之后的内容,然后您可以使用此简单模式捕获该网址的该部分,然后将其重复为参数这里:
<rewrite>
<rules>
<rule name="client1 rewrite">
<match url="^([^/.]*)[/]*$" />
<action type="rewrite" url="login.aspx?client={R:1}"/>
</rule>
</rules>
</rewrite>
这是有效的,因为在所有忽略列表中,&#34; middle&#34;中有斜杠,但斜杠在&#34;过滤器&#34;结束时是可选的。名单。因此,如果没有斜杠,{R:1}
将包含第一个斜杠或url结尾的所有内容。