IIS server url rewrite - iis

For example, I have a domain example.com and my server IP is 1.1.1.1 that is running Microsoft IIS server on Windows Server 2016 Datacenter
The DNS record is A *.example.com 1.1.1.1
I want to make the server, 1.1.1.1 display the contents under C:\inetpub\*
If the directory doesn't exist, the server should return a 404 error.
For example:
The file system:
|--C:\
|-- inetpub\
|-- a
|-- b
|-- c
will results:
a.example.com show contents under C:\inetpub\a
b.example.com show contents under C:\inetpub\b
c.example.com show contents under C:\inetpub\c
d.example.com return HTTP/1.1 404 Not Found
Thanks.

Please map these folders as virtual directory under your website.
For example: /a->c:\inetpub\a. /b->c:\inetpub\b.
Then you can easily rewrite a.example.com/test.aspx to a.example.com/a/test.aspx. If the folder does not exist. Then d.example.com/d/ will just return 404.
<rule name="rewrite">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*)\.example\.com" />
</conditions>
<action type="Rewrite" url="{C:1}/{R:1}" />
</rule>

Related

How IIS 80 port webstie set one sub-app only intranet and other internet?

e.g,my iis folder directory structure like :
IIS
|-default app (80 port)
|- Aapp
|- Bapp
|- Capp
I can set all 80 port app have internet premission,but i have trouble when I'd like to set Aapp only intranet premission and other app Bapp,Capp have internet premission.
expected :
user on internet link https://mycompany.com/Aapp get 404 status code
user on intranet link https://192.168.1.1/Aapp get 200 status code
user on internet link https://mycompany.com/Bapp get 200 status code
If your intranet IP segement looks like 192.168.x.x. Then you could set the rule like this to exclude intranet IP address. In this case, all IP doesn't match your intranet net will be blocked by Aapp.
<rule name="rewrite rule1" stopProcessing="true">
<match url="Aapp" />
<conditions>
<add input="{REMOTE_ADDR}" pattern="192\.168\.[0-9]+\.[0-9]+" negate="true" />
</conditions>
<action type="CustomResponse" statusCode="404" subStatusCode="0" statusReason="Internet access not allowed" statusDescription="Not found" />
</rule>
If 404 response is not necessarily.Then you can set domain and IP restriction rule for each application.
https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/hh831785(v=ws.11)

How to redirect all request to root directory on IIS server?

I have a directory that looks like this:
/root
/home
/about
index.html
My example.com domain points to my root directory and I want to configure all requests like example.com/home or example.com/about to stay in the root directory and return the index.html.
This rule will rewrite all (including css,js, and other resources) non-homepage requests to your index.html on the root.
<rule name="rewrite to index" enabled="true" stopProcessing="true">
<match url="^$" negate="true" />
<action type="Rewrite" url="/index.html" />
</rule>

IIS Canonical Domain Name with Exception for internal domain

I've got a site in IIS that has 2 domain bindings associated with it:
- mysite.com
- internal.mysite.com
The users inside the network user the internal.mysite.com and outside uses mysite.com.
I'd like to setup a canonical domain name rule so the outside users going to mysite.com are redirected to the www version (www.mysite.com).
But, when I setup the redirect, the internal.mysite.com users are also directed to the www site.
Is it possible to create an exception so that the internal.mysite.com domain is NOT redirected? Or, do I have to create a separate site in IIS?
Thanks!
It is possible, your rule should be like that:
<rule name="Redirect example.com to www" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" />
</rule>
You just need to replace example.com with your actual domain name

Rewrite to Subdomain from Domain Pointer

I have a domain (www.example.com) with a subdomain (test.example.com)
I also have a domain pointer (www.pointer.com) pointing to www.example.com
What I would like to do is have anybody who types in www.pointer.com in the browser view test.example.com
<rule name="CanonicalHostNameRule1" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.pointer.com" />
</conditions>
<action type="Rewrite" url="test.example.com" />
</rule>
</rules>
but that just sends me to a HTTP Error 404.0 - Not Found page
Is there any way to pull this off?
This is running on IIS (windows) with php
You will need to change the action type to Redirect. A rewrite will only invoke a different resource on the server but will not change the URL in the browser. Other than that your rule looks good to me.

Redirect https://subdomain.example.com to https://example.com/some-web-page in IIS

I have a subdomain (subdomain.example.com) that I want to redirect it to this Url format on my website https://example.com/some-web-page.
I created an empty site in IIS, the site only contains a web.config file with this rule:
<rule name="subdomain.example.com Redirect" stopProcessing="false">
<match url="^\/?$" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*subdomain\.example\.com.*" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://example.com/some-web-page/{R:0}" />
</rule>
Now, subdomain.example.com is redirecting as it should but https://subdomain.example.com is taking me to https://example.com home page and the address bar shows an error saying "The identity of the website has not been verified. Server's certificate does not match the Url."
I should also mention that I have purchased an additional certificate for https://subdomain.example.com.
How can I make this https redirect to work in such scenario?

Resources