asp.net - IIS 7.5 Canonical URL Rewrite rules for multiple domains -


in context of url rewrite 2.0 in iis 7.5, want able enforce canonical domain names multiple domains multi-country site, in few rules possible. this:

<rule name="uk host name">     <match url="(.*)" />     <conditions logicalgrouping="matchall">         <add input="{http_host}" pattern="^company\.co\.uk$" />         <add input="{http_host}" pattern="^company\.co$" />         <add input="{http_host}" pattern="^company\.org$" />         <add input="{http_host}" pattern="^company\.net$" />         <add input="{http_host}" pattern="^company\.uk\.com$" />         <add input="{http_host}" pattern="^www\.company\.co\.uk$" negate="true" />     </conditions>     <action type="redirect" url="http://www.company.co.uk/{r:1}" /> </rule> <rule name="france host name">     <match url="(.*)" />     <conditions logicalgrouping="matchall">         <add input="{http_host}" pattern="^company\.fr$" />         <add input="{http_host}" pattern="^company-france\.com$" />         <add input="{http_host}" pattern="^www\.company\.fr$" negate="true" />     </conditions>     <action type="redirect" url="http://www.company.fr/{r:1}" /> </rule> 

the problem above, believe, each of conditions must true hence logicalgrouping="matchall" if changed matchany last condition (with negate="true") ignored, meaning run redirect rule if user visiting correct domain.

the alternative can think of having separate rewrite rule every single different domain, there vast numbers of domains , messy. there plenty of other rewrite rules , maps is.

how can create more complex sets of conditions, rather or any?

the trick combine domains want match against 1 rule or | operator have 1 'positive' rule , 1 'negative' rule should matchall. e.g.:

<rule name="uk host name">     <match url="(.*)" />     <conditions logicalgrouping="matchall">         <add input="{http_host}" pattern="^company\.(co(\.uk)?|org|net|uk\.com)$" />         <add input="{http_host}" pattern="^www\.company\.co\.uk$" negate="true" />     </conditions>     <action type="redirect" url="http://www.company.co.uk/{r:1}" /> </rule> <rule name="france host name">     <match url="(.*)" />     <conditions logicalgrouping="matchall">         <add input="{http_host}" pattern="^company(-france)?\.(fr|com)$" />         <add input="{http_host}" pattern="^www\.company\.fr$" negate="true" />     </conditions>     <action type="redirect" url="http://www.company.fr/{r:1}" /> </rule> 

this might give slight chance regular expression matches many domain names. e.g. pattern pattern="^company(-france)?\.(fr|com)$" matches company.com might not desirable. in case have more specific , e.g. change pattern pattern="^company\.fr|company-france\.com$".


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -