URL Rewrite Outbound Rule fails - url

I have two outbound rules that append ICSearch in front of the match. The following works-
<rule name="RewriteString" preCondition="ResponseIsHtml1">
<match filterByTags="None" pattern="/Backflow/index\?handler=" ignoreCase="true" />
<action type="Rewrite" value="ICSearch{R:0}" />
</rule>
<rule name="RewriteString2" preCondition="ResponseIsHtml1">
<match filterByTags="None" pattern="/Plumbing/index\?handler=" ignoreCase="true" />
<action type="Rewrite" value="ICSearch{R:0}" />
</rule>
I would like to make it more generic and create a regex that will match regardless of the directory.
I have tried
<rule name="RewriteString2" preCondition="ResponseIsHtml1">
<match filterByTags="None" pattern="(*.)\?handler=" ignoreCase="true" />
<action type="Rewrite" value="ICSearch{R:0}" />
</rule>
but it does not rewrite the values. Any ideas on what I am doing wrong?
Thanks

Related

IIS URL Rewrite does not work on a complex URL

I have 2 URL redirection rules:
<rewrite>
<rules>
<clear />
<rule name="al - helyek/al (kieg)" enabled="true" stopProcessing="true">
<match url="^test1/al/(.*)RootFolder=%2Ftest1(.*)" />
<action type="Redirect" url="helyek/al/{R:1}RootFolder=%2Fhelyek{R:2}" />
</rule>
<rule name="al - helyek/al" enabled="true" stopProcessing="true">
<match url="^test1/al/(.*)" />
<action type="Redirect" url="helyek/al/{R:1}" />
</rule>
</rules>
</rewrite>
But the first doesn't work, only the second.
Test URL: http://test:29001/test1/al/Megosztott%20dokumentumok/Forms/AllItems.aspx?RootFolder=%2Ftest1%2Fal%2FMegosztott%20dokumentumok%2FTeszt&FolderCTID=0x01200077BA4D1F1CDCF3498096871FD748FB37&View=%7B70C95A37%2D4FE1%2D4A60%2DA100%2D61E529A1DB56%7D
This is a SharePoint Site Collection.
What could be the problem?
According to your description, RootFolder seems to be the content in the query string. If you need to match the content in the query string, you need to use the server variable {querystring} to match it.
This has a similar issue:
IIS URL Rewrite not working with query string
I found correct redirect:
<rule name="WEBHELY - helyek/WEBHELY (RootFolder)" stopProcessing="true">
<match url="^WEBHELY/(.*)" />
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)?RootFolder=%2FWEBHELY(.*)" />
</conditions>
<action type="Redirect" url="helyek/WEBHELY/{R:1}?RootFolder=%2Fhelyek%2FWEBHELY{C:2}" appendQueryString="false" />
</rule>
<rule name="WEBHELY - helyek/WEBHELY" stopProcessing="true">
<match url="^WEBHELY/(.*)" />
<action type="Redirect" url="helyek/WEBHELY/{R:1}" />
</rule>

URL Rewrite redirect one page to another similar page

How do I redirect 2 similar URLs to 2 different URLs using URL Rewrite or web.config in IIS?
My 2 old URLs are:
http://example.com/used-2-3/
http://example.com/used-2-3-2/
My 2 new URLs are
http://example.com/eq/ex?action=283
http://example.com/eq/ex?action=435
So My web.config rewrite rules are like this, but it is not working
<rule name="Used Conveyors Redirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="http://example.com/used-2-3/" />
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="http://www.example.com/used-2-3/" />
</conditions>
<action type="Redirect" url="http://example.com/eq/ex?action=283" redirectType="Permanent" />
</rule>
<rule name="Used Power Vans" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="http://example.com/used-2-3-2/" />
<add input="{HTTP_HOST}{REQUEST_URI}" pattern="http://www.example.com/used-2-3-2/" />
</conditions>
<action type="Redirect" url="http://example.com/eq/ex?action=435" redirectType="Permanent" />
</rule>
It is not working because both old links redirect to the first new URL.
Please note that in the rules you wrote there are the conditions logicalGrouping = "MatchAll" which means that ALL must match to be considered. I think you should use "MatchAny"...
Anyway why don't you use a simple rule like this?
<rule name="1stOLD" stopProcessing="true">
<match url="^used-2-3\/$" />
<action type"redirect" url="/eq/ex?action=283" />
</rule>
<rule name="2ndOLD" stopProcessing="true">
<match url="^used-2-3-2\/$" />
<action type"redirect" url="/eq/ex?action=435" />
</rule>
this 2 rule capture both http://www.example.com and http://example.com without specify it.
The "Match url" say:
^ : start with
used-2-3 : matches the characters used-2-3 literally
\/ : matches the character / literally
$ : the end of the string

Adding a "?" using IIS URL Rewrite

I need to create an URL rewrite so that when the users type: mydomain.com/test123 the server gets: mydomain.com/?test123.
I tried this:
<rule name="UF" stopProcessing="true">
<match url="example.com/([_0-9a-z-]+)" />
<action type="Redirect" url="https://example.com/?{R:1}" />
</rule>
According to your description, I suggest you could try to use below url rewrite rule.
<rule name="UF" stopProcessing="true">
<match url="([_0-9a-z-]+)" />
<action type="Redirect" url="https://example.com/?{R:1}" appendQueryString="false" />
</rule>
Result:

IIS URL Rewrite remove folder and redirect to other domain

I have two domains, www.example.com and www.example.xx.
When I'm visiting example.com and change language, my adress changes to example.com/xx. In this case I want to redirect do another domain suffix like example.xx instead. But I still want to forward the full address path.
For example: http://example.com/xx/one/two/three/four/five/?query=string should redirect to http://example.xx/one/two/three/four/five/?query=string
I have tried several ways, but with no luck.
<rewrite>
<rules>
<rule name=".com xx Redirect" stopProcessing="true">
<match url="(www\.)?example\.com\/xx\/.*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="^xx\/(.*)" />
</conditions>
<action type="Redirect" url="http://example.xx/{C:1}" appendQueryString="true" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
match url only matches the path not the domain. You will have to do something like this:
<rule name=".com xx Redirect" stopProcessing="true">
<match url="^xx/(.*)" />
<conditions >
<add input="{HTTP_HOST}" pattern="^(www\.)?example\.com$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="http://example.xx/{R:1}" appendQueryString="true" />

iis7 url rewrite for webforms aspx to mvc page

I have had a website with /contact.aspx which gets a succesful redirect to /contact
But I want to redirect my old /content.aspx?contentid=123 to /about/123
Here is my redirect XML part in my web.config:
<rewrite>
<rules>
<rule name="contact" patternSyntax="Wildcard" stopProcessing="true">
<match url="contact.aspx" />
<action type="Redirect" url="Contact" redirectType="Found" />
</rule>
<rule name="Content" patternSyntax="Wildcard" stopProcessing="true">
<match url="content.aspx?contentID=*" />
<action type="Redirect" url="About/{R:1}" appendQueryString="false" redirectType="Found" />
</rule>
</rules>
</rewrite>
Visiting mydomain.com/content.aspx?contentid=123 gives me a 404.
also tried without appendQueryString="false"
Seems easy to fix to me, but I am missing something...
using a regex instead of wildcard also gives a 404:
<rule name="Content">
<match url="content.aspx?contentID=([0-9]+)" />
<action type="Redirect" url="About/{R:1}" redirectType="Found" />
</rule>
From IIS rewrite module configuration documentation.
The URL string that is evaluated against the pattern does not include the query string. To include the query string in the rule evaluation you can use the QUERY_STRING server variable in the rule’s condition.
So after a big of test jiggery-pokery, I think this should work:
<rule name="Content" patternSyntax="ECMAScript" stopProcessing="true">
<match url="content.aspx" />
<conditions>
<add input="{QUERY_STRING}" pattern="contentID=([^&]+)" />
</conditions>
<action type="Redirect" url="About/{C:1}" redirectType="Found" appendQueryString="False" />
</rule>

Resources