Using URL Rewrites to allow 1 IP address to host two subdomains - iis

I have a scenario where I need to two different subdomains to come through the firewall and be rewritten or redirected to areas on the server. For example if I have sub1.mydomain.com/testsub1.html entered externally, I want it to hit the IIS "Default web site/folders/sub1/testsub1.html" and likewise, if sub2.mydomain.com/testsub2.html is received I want it to go to "Default web site/folders/sub2/testsub2.html". We were told that URL Rewritew would be the way to go on this. So we set up rules in the Default web site, to use the MatchURL pattern for:
1. sub1.mydomain.com(.) and to rewrite it to "Default web site/folders/sub1(R:1)" with the action type of Rewrite.
2. sub2.mydomain.com(.) and to rewrite it to "Default web site/folders/sub2(R:1)" with the action type of Rewrite.
If I hit http://sub1.mydomain.com/testsub1.html, I get a file not found error. What I am seeing in the logs is the GET /testsub1.html. If I change the URL to http://sub1.mydomain.com/folders/sub1/testsub1.html, it works perfectly and I see GET /folders/sub1/testsub1.html in the logs and the proper page is displayed in the browser.
What am I missing to make this work without the full path?

Bindings are the best way to handle this. They can listen on the same IP address for different hostnames. Create two separate websites in IIS and configure each of their bindings for that particular subdomain.
More information: http://blogs.technet.com/b/chrad/archive/2010/01/24/understanding-iis-bindings-websites-virtual-directories-and-lastly-application-pools.aspx

Related

IIS: Can I prevent traffic to IP Address and only allow domain name

Since I am using a host header filtering technique in my ASP.NET MVC application, I would like to prevent users from browsing directly to the IP address of my site, and force them to use the FQDN. Is this possible?
I see similar SO question here with no answer
You can do this with Bindings in IIS (assuming you're using IIS): https://technet.microsoft.com/en-us/library/cc731692(v=ws.10).aspx
Open IIS
Right click your site
Click "Edit Bindings"
Edit the entries (http/https) to include a "Host Name" (ex. "YourSite.com", "sub.YourSite.com", etc...)
An alternative would be to force a redirect to the FQDN in your code. You should be able to determine the url using a ServerVariable: https://msdn.microsoft.com/en-us/library/system.web.httprequest.servervariables(v=vs.110).aspx
You can add another Website in IIS, locate it to an empty directory to make it don't do anything useful, use 80 port but don't bind any hostnames. In this case, who access your server by IP directly would just hit this Website, they won't bother you anymore.
Or maybe you can put some helpful webpages in this website to help your client visit by domain name correctly.

IIS Server Subdomain Redirection

I have a Windows Server 2012, with IIS 8 installed. I have multiple websites there. I also have the Default Website.
When I create a new website like www.abc.com and abc.com, it works fine. However, when a customer enters an invalid subdomain to abc.com (a subdomain definition that is not actually there), like xyz.abc.com, it automatically redirects to my Default Website which is a landing page.
Instead, I want to return a custom 404 page from IIS. Is that possible?
Thanks.
Your DNS should be taking care of that. If xyz.abc.com doesn't exist in the zone, no browser should be coming even close to IIS.
That is, unless you have a wildcard record configured. It sounds like you might.
Give it a look.

IIS 7 IP address forwarding

I want to move some websites from server 1 to server 2.
My clients have A records pointing to the IP address of server 1. Without updating their DNS records, how can I automatically forward request for those domains from server 1 to server 2?
Thanks
Graham
This image is from an article regarding Exchange, but the IIS settings are relevant.
You can redirect at the HTTP level by specifying a URL redirect in IIS's HTTP Redirect settings:-
However, for this approach to work you will need a new domain for your sites. e.g. if the A record resolves www.example.com to Server 1 you will need to redirect to another URL (e.g. www.example.edu) that already resolves to Server 2.
Another option is to setup a reverse proxy using IIS on Server 1:
Today there was a question in the IIS.net Forums asking how to expose two different Internet sites from another site making them look like if they were subdirectories in the main site.
So for example the goal was to have a site: www.site.com expose a www.site.com/company1 and a www.site.com/company2 and have the content from www.company1.com served for the first one and www.company2.com served in the second one
So slightly different requirements (the article only wants a subdirectory rather than the whole site), but the same concept will apply.

How to display content from another domain by editing CNAME records?

I have a site that lets people have their own e-stores, for ex- mysite.com/clientname
What I want is, if somebody opens store.clientname.com or clientname.com/store, the content is pulled from mysite.com/clientname. [ So that their users feel that they are browsing on their site ]
I know this is possible because site'e like tumblr let you do that by changing a CNAME entry for your domain to their IP address.
I do have a dedicated IP address.
Also, can this be done by editing the .htaccess file at clientname.com, and if yes, which method is better/easy?
You'll want to solve the problem in a completely different way for http://store.clientname.com/ versus http://clientname.com/store.
In the first case, you can serve the web site as a virtual host. Just set up a virtual host called store.clientname.com and set its DocumentRoot to be the existing directory that contains the files for http://mysite.com/clientname. If you have other web server configuration directives that apply to http://mysite.com/clientname then you'll also want to apply those in the virtual host. Finally, the client can set up a CNAME record in DNS for store.clientname.com pointing to your web server.
If you are using Apache, you can also use a default virtual host and mod_rewrite to dynamically translate URLs of the form http://store.{whatever}/ to http://mysite.com/{whatever}/. However, this won't work if you are using HTTPS.
In the second case, you don't want to serve the web site at http://clientname.com/ because the client presumably is already hosting that and presumably http://clientname.com/otherstuff has to continue working and come from their server. So the second case is easier for you because all the work has to be done on the client's web server. But it's simple: they will just have to configure their web server to proxy http://clientname.com/store to http://mysite.com/clientname.

Sharing single application across a 2 subdomains in IIS7

I have an application that is currently deployed (ex. www.example.com ). However, now we have a "secure" subdomain, which will take all of the requests that need to be encrypted (ex. secure.example.com). The site that is at www.example.com is currently mapped to C:\inetpub\example.com\wwwroot\, and I've mapped secure.example.com to C:\inetpub\example.com\wwwroot\secure.
However, since secure.example.com was setup as a new website within the IIS Manager, when the secure site is visited, it displays an error since there is no web.config associated with this website; however, this is the way I want it since I want this to be a part of the application that is in the parent directory.
I think what you really meant to do was just right click on the web site for example.com and edit the bindings. In there you can add host names to that site.
Make sure you add them for port 443 which is SSL.
Map both the IIS virtual directories/web sites to the same directory, and check that are both using the same IIS application name.
(Not tried this, but can't recall seeing anything to say it would not work.)

Resources