Web.config and mapping subdomains to folders

天大地大妈咪最大 提交于 2019-12-13 05:25:17

问题


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.



来源:https://stackoverflow.com/questions/4660717/web-config-and-mapping-subdomains-to-folders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!