Web.config and mapping subdomains to folders

2019-09-13 03:31发布

问题:

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!

回答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]


回答2:

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