bingles
bingles

Reputation: 12203

IIS Multiple Domain Redirect

I currently have 2 domain names that I want to setup different websites for. I am currently looking at using some free hosting that works well for my current needs but doesn't give me any way to point "mydomain.com" to the actual site. Instead I have to give users a longer, harder to remember url.

My proposed solution is to point my domains to my home ip and host a small ASP.NET app through IIS consisting of a redirect page that simply redirects to the appropriate site. Is there a way in ASP.NET to recognize which domain url was requested in order to know where to redirect the page to?

Upvotes: 3

Views: 2786

Answers (2)

Jim
Jim

Reputation: 11379

Here is one way to do it (as recommended by 1and1.com if you host multiple domains). Put this at the root of your web space. All of your websites will point to this root. The script below will forward the requests to the proper subfolder. It's kind of a hack, but if you don't have complete control over the IIS settings, this will work.

Name this file default.asp:

<%EnableSessionState=False

host = Request.ServerVariables("HTTP_HOST")

if host = "website1.com" or host = "www.website1.com" then
response.redirect("http://website1.com/website1/default.aspx")

elseif host = "website2.com" or host = "www.website2.com" then
response.redirect("http://website2.com/website2/default.aspx")

else
response.redirect("http://website1.com/")

end if
%>

Upvotes: 2

Cristian Libardo
Cristian Libardo

Reputation: 9258

From asp.net code you can access the host from the request object:

if(Request.Url.Authority == "www.site1.com")
    Response.Redirect(...);

If you have access to the IIS server you can also set up two sites with different binding host names and have each redirect as you like.

Upvotes: 1

Related Questions