1

I've got three subdomains: dev.mydomain.com, archive.mydomain.com, and www.mydomain.com.

Would it be possible to create a web.config file that will map requests to a given subdomain to a folder sitting in the webroot that matches that subdomain?

E.g. if my D:\inetpub folder contains dev\index.cfm, archive\index.cfm, and www\index.cfm, i'd like to map requests to http://dev.mydomain.com/index.cfm to the first, http://archive.mydomain.com/index.cfm to the second, and http://www.mydomain.com/index.cfm to the third.

Thanks for your consideration!

justinbach
  • 1,945
  • 26
  • 44

2 Answers2

1

I'd recommend that you look into URL Rewriting for this. There's some great paid and free ones out there. They take all requests at the IIS level, compare them to a regular expression table and silently re-map and URLs that you specify.

Depending on what you go with your expressions would be something like:

RewriteCond %{HTTP_HOST} ^(dev|archive|www).mydomain.com$
RewriteRule ^/(.*)$ /$0/$1 [F]
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • Chris, thanks for the response. It looks like you're using .htaccess-style rules, though, and I'm trying to do this in IIS with a web.config file. I didn't think IIS supported .htaccess-style rewriting...am I mistaken? – justinbach Jan 13 '11 at 21:19
  • @justinbach, if you re-read above you'll see that I mentioned using a 3rd-party rewriting engine. Most have rules very similar to htaccess, what I posted I think works in IIRF. The problem with web.config is that it only comes into play when ASP.Net comes into play. But ASP.Net only comes into play for file extensions mapped to it in IIS. So for instance if someone requested a JPG, IIS would just push it to the client or 404 if it couldn't be found, ASP.Net would never be invoked. – Chris Haas Jan 13 '11 at 22:39
  • @Chris--my mistake, sorry. Thanks for making the distinction; I'll investigate and which one might fit the bill. – justinbach Jan 14 '11 at 14:15
  • Just an update for currency... @ChrisHaas states that using web.config is a problem due to ASP.NET. This is less of an issue with IIS7. Since the web request pipeline is now handled by a complete .NET stack, you can apply ASP.NET HTTP modules that can affect any request type, with or without a file extension. Also, in IIS 6 you can set a wildcard rule on a site or virtual direct that forces all requests through the managed request pipeline. (This was the technique for hosting MVC in iis without forcing an extension onto the routes.) – Peter May 30 '13 at 20:02
0

You can do this simply on IIS by using host headers.

Brian
  • 9
  • 1