简体   繁体   中英

Server 2008: Redirect via IIS7 or ASP.NET?

Hopefully a quick and easy question.

I have a domain with several sub-domains. When I attempt to redirect the root (www.example.com and example.com) it works fine, however it also forwards the sub-domains. Each sub-domain, including the root site are setup as individual sites. I don't want to forward the sub-domains only the root site.

Is this possible in IIS7 or should I just code redirect in the Index page(S)? I'm sure there's a way.....

If you are using the Host Headers in IIS and each subdomain is in it's own site, then as long as it matches the host header, it will go to that site before it hits your root site.

If you are actually running them all under one IIS site then you can use the URL rewrite to redirect sub-domains to folders (eg site.domain.com -> domain.com/site).

I'm not entirely clear on the wording in your question, but it sounds like the host headers I mentioned first are causing your issues. If they truly are different IIS sites then check that the host headers are set correctly and they are not being removed/changed by any load balancer, proxy or any other box you have in front of your web server.

Sure its possible, you just need to compare the Request URL host to the name(s) you want to redirect on:

string host = HttpContext.Current.Request.Url.Host.ToLower();
if (host == "redirectme.domain.com")
{
    Response.Redirect("anotherpage.aspx");
}

more info

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