views:

671

answers:

4

Hi, i have got below rule that works fine with standart domain names like .net.com,.mobi but if domain name has 2 parts like co.uk it doesn't work.

How can i adjust it so it would work with .net,.com and .co.uk at same time?

      <if header="HTTP_HOST" match="^(?:www\.)?([^.]+)\.([^.]+)\.([^.]+)$">
   <set property="subdomain" value="$1"/>
   <set property="domain" value="$2"/>
   <set property="tld" value="$3"/>
   <rewrite url="~/default.aspx" to="~/PageEngine.ashx?subdomain=${subdomain}&amp;domain=${domain}.${tld}&amp;defaultpage=yes" processing="stop"/>
  </if>
A: 

The following regex should work for you:

^(?:www\.)??([^.]+)\.([^.]+)\.([^.]+|[^.]+\.[^.]+)$

The double "?" after the "www" section tells the regex to do a lazy match so it will only match the www if necessary. The final "tld" section will match against one-part (.net or .com) or two-part (.co.uk) domain names.

Templar
thanks. it works as expected
nLL
sorry i have marked it as answer at first but with your solution while subdomain.domain.com works fine www.subdomain.domain.co.uk doesn't – nLL 7 mins ago
nLL
How does it not work for www.subdomain.domain.co.uk?Here are the results I get:subdomain="subdomain"domain="domain"tld="co.uk"
Templar
A: 

This regex, like the one you posted, will match a URL consisting of three components after an optional "www.", except the final component may be "co." or "com." plus any two letters.

^(?:www\.)?([^.]+)\.([^.]+)\.(com?\.[a-z]{2}|[^.]+)$

(Edited to meet expanded requirement from the comment.)

Alan Moore
i have marked 1st answer as "answer" in first place but after a short test i noticed it doesn't work with www.subdomain so i have marked your answer as correct answer. i must note that your answer doesn't work with any other option (such as com.tr)
nLL
If you wanted to match ".co" OR ".com" followed by a ccTLD (country-code top-level domain) as a single unit, you should have said so. There's nothing special about those combinations: the real TLD is still ".uk" or ".tr".
Alan Moore
I should have. I know they are not special but i am looking for a solution that would match .com,.net etc as well as ccTLD
nLL
A: 

hi, I want to create virtual subdomain from Intelligencia.urlrewriter.dll in asp.net Can you please help, how to write rule in web.config and what changes in IIS

Nitin
A: 

hi i have same problem...

i want to filter both domain and sub domain from url..

e.g:http://www.domain1.com.au/domain2

result should be val1= http://www.domain1.com.au & val2=domain2

how can i do this by using url rewriter

amal