IIS Rule Help - Redirection - iis

I need your help to create a Redirection rule in IIS.
You have the following scenario:
When a user types www.mipagina.com, he is redirected to www.miotrapagina.com, except if he enters some routes such as www.mipagina.com/MyApp1, in this case he should not be redirected.
Thanks for your help.

You can use this rule:
<rule name="test" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^mipagina.com$" />
</conditions>
<action type="Redirect" url="http://www.miotrapagina.com/{R:1}" />
</rule>

Related

Have Subdirectory of site in IIS show the index.html file when browsing to site

I am a fairly novice windows IIS guy, so any help I would greatly appreciate.
I have a client that requested all root Urls on their department websites redirect to their index.html page. So if a user, for example, goes to https://mysite.domain.com/, it will redirect to https://mysite.doman.com/index.html.
I did this through IIS 10 using a URLrewrite rule on the root of each site by doing the following.
<rule name="Index Request" enabled="true" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="https://mysite.domain.com/index.html" />
</rule>
This seemed to work.
The client now wants to have any of the subfolders of the root site show the index.html to any subdirectory sites of the root. Example. Https://mysite.domain.com/subdir/ “This is what shows now” to https://mysite.domain.com/subdir/index.html. Is there a way to do this in IIS?
Thanks in advance for any advice
I have made sure the index.html is the default document. I have also looked at User Friendly URL-template https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/user-friendly-url-rule-template, but I am not sure if this is the right direction to go.
You can try this rule:
<rule name="test" enabled="true" stopProcessing="true">
<match url="^$" />
<action type="Redirect" url="/index.html" />
</rule>
<rule name="test1" enabled="true" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/([^/]+)" />
</conditions>
<action type="Redirect" url="/{C:1}/index.html" />
</rule>
<rule name="SEF Rule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}/index.html" matchType="IsFile"
ignoreCase="false" />
</conditions>
<action type="Redirect" url="{R:1}/index.html" />
</rule>

Redirect to another URL in IIS

I want to redirect from one url to another is IIS.
For e.g. my page "Dynamic Graph Viewer" is available at http://localhost:8090
But want it to be available at http://localhost:8090/DynamicViewer
Are you trying to redirect http://localhost:8090 to http://localhost:8090/DynamicViewer? if so, you can try this rule:
<rule name="test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^localhost:8090$" />
</conditions>
<action type="Redirect" url="http://localhost:8090/DynamicViewer" redirectType="Permanent" />
</rule>

IIS UrlRewrite for subdomain to subdirectory

I'm trying to simply do a subdomain rewrite to a directory. Example, http*://member.mydomain.com would redirect to http*://mydomain.com/memberarea/. I don't want ALL subdomains to do this, just the defined "member" one.
Here is the code I have, and it does not work. I'm obviously missing something...
<rule name="Member Pages" stopProcessing="true">
<match url="^(.+)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*)://member\.example\.com($)" />
</conditions>
<action type="Redirect" url="{C:1}://example.com/MemberArea/{R:1}" />
</rule>
My hope is this would also make http://member.example.com/Report/SomeReport.aspx resolve to http://example.com/MemberArea/Report/SomeReport.aspx.
Any help would be greatly appreciated.
You can try this rule will be redirected to the http*://member.mydomain.com http*://mydomain.com/memberarea/
<rule name="test2" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^member\.(.*)$" />
</conditions>
<action type="Redirect" url="http://{C:1}/memberarea" />
</rule>

URL Rewriting the path in IIS

I have a site that uses two characters in the URL path to determine the initial language e.g. https://my.company.net/Monitoring/gb displays in the English language. I want to setup a redirect for these two display the full culture code e.g. https://my.company.net/Monitoring/en-GB
This is the rule that I've tried:
<rewrite>
<rules>
<rule name="Monitoring gb rewrite" patternSyntax="ExactMatch" stopProcessing="true">
<match url="https://my.company.net/Monitoring/gb" />
<conditions />
<serverVariables />
<action type="Redirect" url="https://my.company.net/Monitoring/en-GB" appendQueryString="false" />
</rule>
</rules>
</rewrite>
I expected https://my.company.net/Monitoring/gb to redirect to https://my.company.net/Monitoring/en-GB however this rule does not have any effect: the browser URL stays at https://my.company.net/Monitoring/gb.
How can I rectify this?
You could use below url rewrite rule.
<rule name="gb to en-gb redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="ww.sample1.com" />
<add input="{HTTPS}" pattern="on" />
<add input="{REQUEST_URI}" pattern="Monitoring/gb" />
</conditions>
<action type="Redirect" url="https://www.sample1.com/Monitoring/en-GB" />
</rule>
Note: use your hostname instead of the www.sample1.com.
The redirect failure was due to browser caching. The redirect works once the cache is cleared.

IIS: Redirect subdomain to specific url

In IIS 8, I want to redirect the url http://test.example.com to http://www.example.com/abc/123
I try this, but not work.
<rule name="test" stopProcessing="true">
<match url="^test.example.com$" />
<action type="Redirect" url="http://www.example.com/abc/123" />
</rule>
you could add the pattern like this
<rule name="RedirectDomain" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="(.*)test.example.com />
</conditions>
<action type="Redirect" url="http://www.example.com/abc/123" redirectType="Permanent" />
</rule>
In the IIS GUI on the given side you should be able to choose 'HTTP Redirect' from there you can type in a url to redirect the site to.
I don't know if this approach is the recommended (It is normally used to redirect HTTP request on a given site to use HTTPS), but it will solve your problem.

Resources