I need to write rewrite rules in IIS that will redirect to https://example.com/xml.
So
case 1: https://example.com/test
case 2: https://example.com/[country-lang-token]/test
(e.g https://example.com/en-us/test and
https://example.com/fr-fr/test)
should be redirect to https://example.com/xml.
I know how to write rewrite rules but stuck due to regular expression.
Your rule should be like this:
<rule name="Redirect to xml" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="^/test$" />
<add input="{REQUEST_URI}" pattern="^/\w{2}-\w{2}/test$" />
</conditions>
<action type="Redirect" url="/xml" />
</rule>
First condition is for case 1 url https://example.com/test
Second condition is for case 2 https://example.com/[country-lang-token]/test where [country-lang-token] is string in format {two_letters}-{two_letters}
Related
I have a working rule that removes www. for all urls coming in. I have a webserivce that the redirect will change from a POST to a GET. I need to exclude the URL https://www.foo.net/WebServices/service.asmx from this rule.
I have looked at other solutions on SO with no success.
<rewrite>
<rules>
<rule name="Remove WWW" enabled="true" stopProcessing="true">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^(www\.)(foo\.net)" />
</conditions>
<action type="Redirect" url="https://{C:2}/{R:1}" />
</rule>
</rules>
</rewrite>
You can do that easily by adding a condition to "not match" (aka adding "negate='true'" ), something like this should work:
<rules>
<rule name="Remove WWW" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.foo\.net$" />
<add input="{URL}" pattern="^/WebServices/service\.asmx$" negate="true" />
</conditions>
<action type="Redirect" url="https://foo.net/{R:1}" />
</rule>
</rules>
I have a directory at etreecycle.co.uk/austincollins/.
I want to point the subdomain austin.etreecycle.co.uk to /austincollins/.
Inside /austincollins/ there is a folder called /test/.
So to get to /austincollins/test/ the url should be austin.etreecycle.co.uk/test/.
But the url shows as austin.etreecycle.co.uk/austincollins/test/.
Here is the Rewrite rule:
<rule name="austin.etreecycle.co.uk" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^austin.etreecycle.co.uk$" />
<add input="{PATH_INFO}" pattern="^/austincollins/" negate="true" />
</conditions>
<action type="Rewrite" url="\austincollins\{R:0}" />
</rule>
How can I remove the /austincollins/ from the URL, and why is is showing?
Also:
When you go to austin.etreecycle.co.uk it shows the index file in /austincollins/. This is why I don't understand why you have to go to austin.etreecycle.co.uk/austincollins/dev/ and not just /dev/.
Rule is
<rule name="Redirect to new host" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern=".*mycompany\.com/blogs(.*)" />
</conditions>
<action type="Redirect" url="http://blogs.mycompany.com{C:1}" />
</rule>
The module's built-in pattern tester says that http://subdomain.mycompany.com/blogs/blog1 matches, so it should redirect to http://blogs.mycompany.com/blog1, but nothing happens. Would greatly appreciate help fixing this rule or writing one that does work!
It's work:
<rule name="Test" stopProcessing="true">
<match url=".*" />
<conditions trackAllCaptures="true">
<add input="{HTTP_HOST}" pattern="^.*mycompany\.com$" />
<add input="{URL}" pattern="^/blogs(.*)$" />
</conditions>
<action type="Redirect" url="http://blogs.mycompany.com{C:1}" />
</rule>
I already have the following code in my web.config which does pretty much what I want.
<rewrite>
<rules>
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www.mysite.com$" negate="true" />
</conditions>
<action type="Redirect" url="{MapSSL:{HTTPS}}www.mysite.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapSSL" defaultValue="OFF">
<add key="ON" value="https://" />
<add key="OFF" value="http://" />
</rewriteMap>
</rewriteMaps>
</rewrite>
There is just one element missing from what I can see. The query element of the url will remain as is - mixed/upper case - how can I ensure all of the url is lowercase?
You can add a lowercase rule.
<rule name="LowerCaseRule" patternSyntax="ExactMatch" stopProcessing="true">
<matchurl="[A-Z]" ignoreCase="false"/>
<actiontype="Redirect" url="{ToLower:{URL}}"/>
</rule>
its part of default template, Under Search Engine Optimization (SEO) template, select Enforce lowercase URLs
I have a problem as follows:
I want to rewrite from /index.php?jobs to /index.php?retail-jobs-in-london
and I tried the following rule:
<rule name="jobs" stopProcessing="true">
<match url="index.php$" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="jobs" />
</conditions>
<action type="Redirect" appendQueryString="false" url="http://www.domain.com/index.php?retail-jobs-in-london" />
</rule>
However, I get an error for the intended page /index.php?retail-jobs-in-london, I believe because "jobs" is in the query string for the intended page, so it tries to loop.
How can I explicitly look for a query string which is exactly and only "jobs"?
Thanks in advance
This should work.
Change this line so the regex matches the start and end of the string:
<add input="{QUERY_STRING}" pattern="^jobs$" />
Or you could change it to match only if it starts with "jobs", which would handle when other things have been added to the end:
<add input="{QUERY_STRING}" pattern="^jobs" />