简体   繁体   中英

Url rewriting like as sub domain

I have a domain mysite.com which hosts asp.net website. I want to add virtual sum-domain user1.mysite.com , user2.domain.com etc without adding sub-domain under DNS.

I have tried couple URL rewriting option suggested in Stackoverflow itself. but it didn't work.

when hit www.mysite.com it taking to me the redirect/rewrite path. but other than www everything loads with default IIS7 page. Do we really need sub-domain to be created under DNS?

Can't we do it programmatically?

Can you anyone please explain in a step by step to implement this?

Of course you can achieve it in IIS 7 (proof: http://learn.iis.net/page.aspx/468/using-global-and-distributed-rewrite-rules/ )

The main point is defining your custom regex and action pattern to rewrite your plain ASPX pages into custom subdomain format.

However, the rewrite rule still have chance to overwrite "www" before your domain name (eg www.example.com). To prevent this weird behavior, add this condition at beginning of rewrite collection:

<add input="{HTTP_HOST}" pattern="^www\." negate="true" />

Source: https://forums.iis.net/t/1161322.aspx?URL+rewrite+for+subdomain+to+subfolder

I hope this explanation helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM