I got the Virtual Host in my IIS:
http://sampleserver.org
I want to redirect this URL to a tomcat application http://localhost:8081/one
But I donĀ“t want to redirect the url
http://sampleserver.org/two to http://localhost:8081/one/two
So my rule looks like this:
<rule name="Root zu Client" enabled="true" patternSyntax="ECMAScript" stopProcessing="false">
<match url=".*" ignoreCase="false" negate="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{REQUEST_URI}" pattern="^two" negate="true" />
</conditions>
<action type="Rewrite" url="http://localhost:8081/one/{R:0}" logRewrittenUrl="true" />
</rule>
I want to redirect everything but ^two to the tomcat.
Is this not possible or am I missing something?
Pattern is not correct. If you don't want redirect url like http://sampleserver.org/two you must apply this:
<rule name="RuleTWO" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{REQUEST_URI}" pattern="*/two*" negate="true"/>
</conditions>
<action type="Rewrite" url="http://localhost:8081/one/{C:2}" />
</rule>
Related
I am trying to redirect the two links below to the root.
My question is can you see a problem with my rule written below?
Thank You!
http://pollen.aaaai.org/nab/collectors/
http://pollen.aaaai.org/nab/collectors/index.cfm?p=Count_form
<rule name="Redirect /nab/collectors/ to http://pollen.aaaai.org/" patternSyntax="Wildcard" stopProcessing="false">
<match url="*/nab/collectors/*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Rewrite" url="http://pollen.aaaai.org" appendQueryString="false" />
</rule>
There is a problem with your parameter, it matches the content after the hostname and does not contain "/". you can refer to below rule about redirect to root.
Note: I changed patternSyntax from wildcards to regular expressions.
<rule name="Redirect /nab/collectors/ to http://pollen.aaaai.org/" patternSyntax="Regular Expressions" stopProcessing="false">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Rewrite" url="http://pollen.aaaai.org" appendQueryString="false" />
</rule>
I have tried all kinds of rewrite URL's and can't get IIS to send the URL of https://example.com/default.aspx/default.aspx to https://example.com/default.aspx
Google has indexed the site with the wrong URL when Bing got it right (go figure). Any help would be much appreciated. All my traffic is going to the wrong url (https://example.com/default.aspx/default.aspx).
<rewrite>
<rules>
<rule name="Redirect www.xxx.com to xxx.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^https://example.com/default.aspx/default.aspx" />
</conditions>
<action type="Redirect" url="default.aspx" />
</rule>
<rule name="redirect two character to default" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{URL}" pattern="^/[a-z]{2}(/)?$" />
</conditions>
<action type="Redirect" url="default.aspx" appendQueryString="false" />
</rule>
</rules>
</rewrite>
There is some issue in your rule. {HTTP_HOST} only matches the hostname which is www.example.com it will not match the whole URL.
You could try below rule:
<rule name="Redirect www.xxx.com to xxx.com" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.example.com" />
<add input="{HTTPS}" pattern="on" />
<add input="{REQUEST_URI}" pattern="default/default|default.aspx/default.aspx" />
</conditions>
<action type="Redirect" url="default.aspx" />
</rule>
I'm trying to write a IIS Url rewrite rule that redirects all requests except two, and I can't figure it out.
What I'm trying to accomplish:
http://server/healthcheck.aspx --> not redirected
http://server/idsrv2/2/stuff --> not redirected
http://server/stuffstuff --> redirect to http://server/idsrv2/stuffstuff
This is the rule I have so far, but it's not kicking in:
<rule name="Redirect everything to idsrv/2" patternSyntax="Wildcard" stopProcessing="true">
<match url="^$" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="^(.*)healthcheck" negate="true"/>
<add input="{REQUEST_URI}" pattern="^(.*)idsrv2" negate="true" />
</conditions>
<action type="Redirect" url="idsrv2{R:1}" appendQueryString="true"/>
</rule>
Any help appreciated!
Logical grouping in your rule should be MatchAll. I've changed you rule a bit and this should work in your case:
<rule name="Redirect everything to idsrv/2" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="^/healthcheck" negate="true"/>
<add input="{REQUEST_URI}" pattern="^/idsrv2" negate="true" />
</conditions>
<action type="Redirect" url="idsrv2/{R:0}" appendQueryString="true" />
</rule>
I'm trying to wrap my head around this problem;
I have a default site with an application that resides in a subfolder, e.g. /app/app.html
It also accepts a language parameter, so for example http://192.168.0.1/app/app.html?language=fi would work.
Now I have two subdomains that I need to not only get rewritten to the correct folder, but also include the language parameter. For example:
fi.domain.com -> http://1.1.1.1/app/app.html?language=fi
swe.domain.com -> http://1.1.1.1/app/app.html?language=swe
I've made A records for both subdomains to point to 1.1.1.1
Currently there are no special bindings (only port 80, no hostnames and all IPs) and no special default pages.
EDIT: I've tried using the URL rewriter module, but I haven't been able to get it work as intended.
EDIT 2: My first example of how I need it to work was a bit flawed, here's a better version;
finnishword.domain.com -> http://1.1.1.1/app/app.html?language=fi
otherwordinswedish.domain.com -> http://1.1.1.1/app/app.html?language=swe
I'm not sure to well understand your question.
It seems that you need URL rewriting rules.
According to this link
<rule name="CName to URL - Rewrite" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(.*)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language={C:1}" />
</rule>
I think it's what you need ;)
Edit 24/08/2016
If you can't have a dynmique pattern with RegEx you have to do as many rules as you have subdomains:
<rule name="finnishRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(finnishword)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language=fi" />
</rule>
<rule name="finnishRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(otherwordinswedish)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language=swe" />
</rule>
or you can mixup all together if you want to redirect all subdomains that contains the word "swedish" on url with ?
<rule name="finnishRule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www)(.*swedish.*)\.domain\.com$" />
</conditions>
<action type="Rewrite" url="/app/app.html?language=swe" />
</rule>
So after all the RegEx pattern is up to you ;)
Edit 25/08/2016
Maybe you have to add condition to skip static files
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
...
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<rules>
<clear />
<rule name="swedishMainRule" enabled="true" stopProcessing="true">
<match url="^$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?swedishword\.domain\.fi$" />
<add input="{QUERY_STRING}" pattern="language=" negate="true" />
</conditions>
<action type="Redirect" url="?language=sve" appendQueryString="false" logRewrittenUrl="false" />
</rule>
<rule name="swedishRule" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?swedishword\.domain\.fi$" />
</conditions>
<action type="Rewrite" url="/app/{R:1}" />
</rule>
<rule name="finnishRule" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)?anotherfinnishword\.domain\.fi$" />
</conditions>
<action type="Rewrite" url="/app/{R:1}" />
</rule>
</rules>
This is how I ended up doing it, basically the first rule deal with the language parameter, and the other rules just rewrite the URL. The Finnish rule doesn't need an extra language rule since the default language of the app is Finnish.
I'm trying to write a URL rewrite rule to force a HTTPS connection. This should always happen except when a request is using localhost (e.g. http://localhost/mysite).
The rule is configured as following:
<rule name="Redirect to https" enabled="true" stopProcessing="true">
<match url="(.*)" negate="false" />
<conditions trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{URL}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
I also tried to use ^localhost and ^localhost/(.*) as a pattern for the URL condition with no help.
Does anyone have an idea why this does not work and what a solution for this problem should be?
Your code should look like this instead
<rule name="Redirect to https" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>