Subdomain routing in ASP.Net Core 5.0

1k Views Asked by At

I have an application developed in dot net core 5.0 with the domain india.com Now I have to bind dynamic subdomain to domain india.com. Example: br.india.com, sa.india.com, rs.india.com, ax.india.com, .... and so on.

Challenging work is that I want all subdomain binding dynamic it won't be static. that will be handled from the database.

Anyone could please help me. Thank you in advance.

1

There are 1 best solutions below

0
foad abdollahi On

Base of your Webserver (IIS, Nginx,...) is difference:

IIS: web.config need add rewrite role :

Redirecting a domain to a subdirectory

<rule name="CustomRule" enabled="true" patternSyntax="Wildcard" stopProcessing="true">  
 <match url="*.mydomain.com" />  
 <action type="Rewrite" url="http://example.com/{R:0}" /> 
</rule>

Nginx:

server {
    listen      80;
    server_name *.example.com; 
    return 301 https://$host$request_uri;
}