I'm using the IIS Rewrite Module on IIS7.5. My mappings is in a text file in the structure:
[old url], [new url]
So something like this works:
products/abc, http://test.com/new/products/abc
This uses the following rule in my web.config
<rule name="FileMapProviderRule" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{FileMapProvider:{R:1}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" redirectType="Permanent" />
</rule>
What will my rule be if i want querystrings to be passed too? So i want this to work:
products?sku=123, http://test.com/new/products/123
products?sku=789, http://test.com/new/products/789
I solved this by the following rule:
<rule name="Products" patternSyntax="Wildcard" stopProcessing="true">
<match url="products" />
<conditions>
<add input="{QUERY_STRING}" pattern="sku=*" />
</conditions>
<action type="Redirect" url="http://test.com/new/products/{C:1}" appendQueryString="false" redirectType="Permanent" />
</rule>
Related
I am trying to remove the last part of the URL with IIS Rewrite, but somewhere I do the things wrong.
Example URL:
https://example.com/BGLog/pages/register/?ReturnUrl=/blog/arebemagare/site/posts/?bid=37780&PageSpeed=noscript
I need to remove &PageSpeed=noscript
I wroted rule, but it strips also ?ReturnUrl=/blog/arebemagare/site/posts/?bid=3778 :
<rule name="Remove paging parameters" stopProcessing="true">
<match url="(.*)?$" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="(.*)(.*)&PageSpeed=noscript(.*)" />
</conditions>
<action type="Redirect" url="{R:1}" appendQueryString="false" redirectType="Temporary" />
Any suggestion? Thanks!
I think I've achieved it, but with two rules:
<rule name="Remove &PageSpeed" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="(.*)(&PageSpeed=noscript)" />
</conditions>
<action type="Redirect" url="{R:1}?{C:1}" appendQueryString="false" redirectType="Found" />
</rule>
<rule name="Remove ?PageSpeed" enabled="true" stopProcessing="true">
<match url="(.*)?$" />
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)(PageSpeed=.+)(.*)" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="false" redirectType="Permanent" />
</rule>
Please try the following ruleļ¼
<rewrite>
<rules>
<rule name="test" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)&(PageSpeed=noscript)" />
</conditions>
<action type="Redirect" url="{R:1}?{C:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
The result of my test is working, hope this works for you too.
It works! But I found it catches also https://example.com/BGLog/blog/filteredlist?cat=5021&PageSpeed=noscript and rewrites it to
https://example.com/BGLog/blog/filteredlist
I've tried to edit it to not strip ?cat=5021, but without success :(
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 am trying to redirect from one site to another like the following.
http://example.com/quickscan/?code=123456
To
https://example2.com/as-quickscan/login?username=123456
The domains are different. Also the redirect URL parameter and URL structure is entirely different.
What I have tried is the following and some other variations.
<rule name="Redirect quickscan" stopProcessing="true">
<match url="^quickscan/\?[a-zA-Z]+=([0-9]+)?$" ignoreCase="true" />
<action type="Redirect" url="https://example2.com/as-quickscan/login?username={R:1}" appendQueryString="false"/>
</rule>
<rule name="Redirect quickscan" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions>
<add input="{QUERY_STRING}" pattern="^quickscan/\?[a-zA-Z]+?=([0-9]+)?$" />
</conditions>
<action type="Redirect" url="https://example2.com/as-quickscan/login?username={R:1}" redirectType="Permanent" appendQueryString="false" />
</rule>
This is fixed. I used the following.
<rule name="Redirect quickscan" stopProcessing="true">
<match url="^quickscan/" ignoreCase="false" />
<conditions>
<add input="{QUERY_STRING}" pattern="([a-z]+)=([0-9]+)" />
</conditions>
<action type="Redirect" url="https://example2.com/as-quickscan/login?username={C:2}" appendQueryString="false" />
</rule>
I'm trying to implement simple IIS URL rewrite. I want to rewrite URL: about.test.local to text.local/about.html .
In configuration below I have added rules, but it doesn't seem to work. What is the problem?
<rewrite>
<rules>
<rule name="Rewrite1" patternSyntax="ExactMatch" stopProcessing="true">
<match url="about.test.local" />
<action type="Rewrite" url="http://test.local/about.html" />
</rule>
<rule name="Rewrite2" patternSyntax="ExactMatch" stopProcessing="true">
<match url="http://about.test.local/" />
<action type="Rewrite" url="http://test.local/about.html" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
As #beavel mentioned, I have added following rules, but URL still doesn't get rewritten:
<rule name="Rewrite2a" patternSyntax="ExactMatch" stopProcessing="true">
<match url="(.+)" />
<conditions>
<add input="{HTTP_HOST}" pattern="about.test.local" />
</conditions>
<action type="Rewrite" url="http://test.local/about.html" />
</rule>
<rule name="Rewrite2b" patternSyntax="ExactMatch" stopProcessing="true">
<match url="(.+)" />
<conditions>
<add input="{HTTP_HOST}" pattern="http://about.test.local/" />
</conditions>
<action type="Rewrite" url="http://test.local/about.html" />
</rule>
The problem is that the match url doesn't contain the host as explained here. If you have multiple hostnames bound to one IIS site and only want to rewrite the one hostname you would do something like:
<rule name="Rewrite1" patternSyntax="ExactMatch" stopProcessing="true">
<match url="(.+)" />
<conditions>
<add input="{HTTP_HOST}" pattern="about.test.local" />
</conditions>
<action type="Rewrite" url="http://test.local/about.html" />
</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>