【发布时间】:2012-02-24 17:45:46
【问题描述】:
我有网址:
http://primarydomain.com/sites/secondarydomain/?foo=bar
我可以使用什么正则表达式来匹配 sites/secondarydomain 的 url - 不区分大小写(这是针对 web.config 文件中的规则,但需要标准正则表达式)?
为了把它放在上下文中,我正在编写一个 web.config url 重写规则以从所有 url 中删除 sites/secondarydomain(由于多个站点托管在同一个包上)。
<rule name="Remove full hosting path">
<match url="***Regex goes here***" ignoreCase="true"/>
<action type="Redirect" url="http://secondary.com/{R:1}" redirectType="Permanent" />
</rule>
我希望仅匹配目录(而不是查询字符串)以重定向用户(因此删除 sites/secondarydomain)。
更新:看起来我想重写 url 而不是重定向,这是当前的 web.config 规则,它不太有效:
<rule name="TestRule">
<match url=".*" />
<conditions>
<add input="{PATH_INFO}" pattern="^(/hostedsites/clemones_htdocs)(/.*)"/>
</conditions>
<action type="Rewrite" url="\{C:2}" appendQueryString="true" />
</rule>
我的辅助域是http://clemones.com/ 以及我想要摆脱的路径:http://clemones.com/hostedsites/clemones_htdocs/
对于测试,http://clemones.com/shizzle 用作目的地(因此遗憾的是,http://clemones.com/hostedsites/clemones_htdocs/shizzle 也可以使用)。
提前致谢
【问题讨论】:
-
您的问题似乎有点模棱两可。您是在尝试匹配站点/辅助域和根更改,还是担心最后的查询字符串 ?foo?还是辅助域是需要正则表达式的变化字段?
-
好的,我想我已经添加了一些说明'辅助域需要正则表达式的变化字段'是正确的。
标签: c# asp.net regex web-config