I want all request that look like:
(www.)mydomain.com/belgium(/*)
to be redirected to:
(www.)mydomain.be
The path and querystring after /belgium/ need to be included:
www.mydomain.com/belgium/page1/page11?filter=yes
Needs to become
www.mydomain.be/page1/page11?filter=yes
<rule name="Rewrite" enabled="true">
<match url="www.mydomain.com/belgium" />
<conditions logicalGrouping="MatchAll" >
<add input="{QUERY_STRING}" pattern="(.+)"/>
</conditions>
<action type="Redirect" url="www.mydomain.be?{C:1}" appendQueryString="true" />
</rule>
<rule name="Rewrite" enabled="true">
<match url="www.mydomain.com/belgium/{.*)" />
<action type="Redirect" url="www.mydomain.be{R:1}" appendQueryString="true" />
</rule>
You can write additional rule to handle www part of the link.
I write this out of my head so it is not correct but I believe it should give you a hint.
Related
Trying to figure out how to do wildcards for querystrings. Right now this works, but it has to be an exact match.
I have this rewrite rule.
<rule name="Redirect rule1 for Redirects ReSv">
<match url=".*" />
<conditions>
<add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="true" />
</rule>
My rewrite maps are like:
<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/contact-us.aspx" value="/contact/" />
<add key="/contact-us/request-information.aspx" value="/contact/" />
</rewriteMap>
</rewriteMaps>
Trying to get something like this:
/contact-us.aspx?q=t&1=2
To redirect to:
/contact/
And include the querystring? so..
/contact/?q=t&1=2
Please us {URL} variable instead of {REQUEST_URI}. Then Rewritemap will be able to wildcard the query string.
<rule name="Redirect rule1 for Redirects ReSv" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{Redirects:{URL}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
I have a website that is served in two languages. I have a domain name for each language, e.g. www.englishsite.com and www.frenchsite.com
The application knows to change languages based on adding this URL parameter:
TemplateCulture=en-CA or TemplateCulture=fr-CA.
However, I am having little success with URL rewrite functionality in web.config to map the sub-domains to the specific language.
Below are the rules I am attempting to use. This isn't working for me, and I am hoping someone can point me in the right direction!
<rewrite>
<rules>
<rule name="redirect" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^http://www.englishsite.com$" />
</conditions>
<action type="Redirect" url="http://www.englishsite.com/?{R:0}TemplateCulture=en-CA" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="redirect2" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^http://www.frenchsite.com$" />
</conditions>
<action type="Redirect" url="http://www.frenchsite.com/?{R:0}TemplateCulture=fr-CA" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
If I understand correctly you are trying to achieve:
If user will visit homepage http://www.englishsite.com it should receive redirect to http://www.englishsite.com/?TemplateCulture=en-CA&{...something...}
If user will visit homepage http://www.frenchsite.com it should receive redirect to http://www.frenchsite.com/?TemplateCulture=fr-CA&{...something...}
Then you rules should be like that:
<rule name="redirect" enabled="true">
<match url="^$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.englishsite.com$" />
</conditions>
<action type="Redirect" url="http://www.englishsite.com/?TemplateCulture=en-CA" appendQueryString="true" redirectType="Permanent" />
</rule>
<rule name="redirect2" enabled="true">
<match url="^$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.frenchsite.com$" />
</conditions>
<action type="Redirect" url="http://www.frenchsite.com/?TemplateCulture=fr-CA" appendQueryString="true" redirectType="Permanent" />
</rule>
Explanation of rules above:
<match url="^$" /> will match only for homepage
<add input="{HTTP_HOST}" pattern="^www.englishsite.com$" /> will create condition when domain name www.englishsite.com
<action type="Redirect" url="http://www.frenchsite.com/?TemplateCulture=fr-CA" appendQueryString="true" redirectType="Permanent" /> will make redirect with culture specific querystring. I removed {R:0} because IIS URL rewrite module will append it automatically because you set appendQueryString="true"
I'm trying to figure out a url rewrite rule to rewrite http requests into https only when a specific path is accessed like below. I've tried quite a few things that in the test pattern seem as though they should work but it never does.
url accessed: http://example.com/books/test.css
I need to check for the http:// and /books/ to form the proper url below.
url needed: https://example.com/books/test.css
A request of http://example.com/book/test.css should be ignored.
You can specify the patten in the <match> element :
<rule name="Force HTTPS for /books/" enabled="true">
<match url="^/books/.*$" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" redirectType="Permanent"
url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="true" />
</rule>
or by adding a new <condition>
<rule name="Force HTTPS for /books/" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
<add input="{REQUEST_URI}" pattern="^/books/.*$" />
</conditions>
<action type="Redirect" redirectType="Permanent"
url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="true" />
</rule>
Can someone explain why this rule is not working? I want a permanent redirect when the querystring below is in the url
<rule name="Telephony Document Lib Redirect" stopProcessing="true">
<match url="(.*)?RootFolder=%2FTechnology%2FShared%20Documents%2FTelephony(.*)" />
<action type="Redirect" url="https://{HTTP_HOST}/sites/teams/Telephony" appendQueryString="false" redirectType="Permanent" />
</rule>
The querystring is separate from the url, and should be matched using a condition, like so:
<rule name="Telephony Document Lib Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="RootFolder=%2FTechnology%2FShared%20Documents%2FTelephony(.*)" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/sites/teams/Telephony" appendQueryString="false" redirectType="Permanent" />
</rule>
I would like to match exactly https://internet.dev.local/KYR url (without / into end) and redirect or rewrite to https://internet.dev.local/KYR/ (with /).
I am trying the following rule but it matches other URLs as well e.g. https://internet.dev.local/KYR/Admin/Form/Default.aspx?signup=false, which is wrong.
so how can I achieve this?
<rule name="Static redirect" patternSyntax="ExactMatch" stopProcessing="true">
<match url="https://internet.dev.local/KYR" negate="true" />
<conditions>
</conditions>
<action type="Redirect" url="/Login/?ReturnUrl=/Member/KYR/" redirectType="Permanent" />
</rule>
If you need to test the host and protocol you have to put it in the conditions, not in the global rule.
Following your example, it would be as follow:
<rule name="test" patternSyntax="ExactMatch" stopProcessing="true">
<match url="KYR" />
<action type="Redirect" url="/KYR/" redirectType="Permanent" />
<conditions>
<add input="{HTTP_HOST}" pattern="internet.dev.local" />
<add input="{HTTPS}" pattern="on" />
</conditions>
</rule>
I have changed the url in the action because your question says:
redirect or rewrite to https://internet.dev.local/KYR/ (with /).
EDIT:
To get it to work on any host (with or without SSL), just remove the conditions:
<rule name="test" patternSyntax="ExactMatch" stopProcessing="true">
<match url="KYR" />
<action type="Redirect" url="/KYR/" redirectType="Permanent" />
</rule>