正则表达式URL匹配除www以外的任何内容 [英] Regex URL match on anything but www
本文介绍了正则表达式URL匹配除www以外的任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用IIS7和URL重写模块.
I'm using IIS7 and the URL Rewrite module.
我想使用正则表达式来匹配www以外的任何子域.
I would like to use regex to match any subdomain apart from www.
所以...
frog.domain.co.uk = Match
m.domain.co.uk = Match
anything.domain.co.uk = Match
www.domain.co.uk = No match
通过这种方式,我可以将有人输入的任何子域重定向回www.
This way I can redirect any subdomain that someone types in back to www.
推荐答案
使用此规则-如果域不同,它将重定向到www.exmaple.com
域:
Use this rule -- it will redirect to www.exmaple.com
domain if domain is different:
<system.webServer>
<rewrite>
<rules>
<rule name="Force www" stopProcessing="true">
<match url="(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.example\.com" negate="true" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
如果您不想两次输入域名(example.com
),则可以对其进行一些优化-但这是非常小的事情,根据您的情况/配置,这可能是不希望的.
You can optimize it a bit if you do not want to type domain name twice (example.com
) -- but that is very minor thing and depending on your circumstances/configuration it is can be undesired.
这篇关于正则表达式URL匹配除www以外的任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文