Url Rewrite Module Not Working When Browsed Too - iis

Why isn't this rule working when I go to a browser with the URL rewrite module?
It works on the regex tester with the url rewrite module.
I even put it at the top of all my rules.
Example url: organizations/51/middle-tennessee-basketball-showcases-basketball-tournaments?page=1
Rewrite rule:
<rule name="Organization Redirect" stopProcessing="true">
<match url="^organizations/(.*)-basketball-tournaments\?page=1$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="organizations/{R:1}" appendQueryString="false" />
</rule>

Your rule should be as following:
<rule name="Organization Redirect" stopProcessing="true">
<match url="^organizations/(.*)-basketball-tournaments$" />
<conditions>
<add input="{QUERY_STRING}" pattern="^page=1$" />
</conditions>
<action type="Redirect" url="organizations/{R:1}" appendQueryString="false" />
</rule>
You should not check the query string (here page=1) in the url test but in the conditions section.

Related

URL Rewrite back reference action URL not working

I have setup a url rewrite rule to redirect from one domain to another in case matching the condition. i have a site abc.aaa.com which should redirect to abc.bbb.com if url matches with *.aaa.com. When I hard code the action URL its working fine but using back reference its not working.
I am using IIS 8.5
Below are the rules.
This is not working. When I am doing this URL is showing http://abc.aaa.com/abc.bbb.com
<rule name="Redirect aaa.com" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*).aaa.com(.*)$" />
</conditions>
<action type="Redirect" url="{C:1}.bbb.com{C:2}" appendQueryString="false" />
</rule>
This is working
<rule name="Redirect aaa.com" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*).aaa.com(.*)$" />
</conditions>
<action type="Redirect" url="http://abc.bbb.com" appendQueryString="false" />
</rule>
I have tried the same pattern in rule pattern and same action without condition. thats also not working
<rule name="Redirect aaa.com" enabled="true" stopProcessing="true">
<match url="(.*).aaa.com(.*)$" />
<action type="Redirect" url="http://abc.bbb.com" appendQueryString="false" />
</rule>
I have found that {C:1} doesn't contain http:// part and seperated that in URL action . it's working fine.Below is the modified rule
Thanks Lex Li for the quick response
<rule name="Redirect aaa.com" enabled="true" stopProcessing="false">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="(.*).aaa.com(.*)$" />
</conditions>
<action type="Redirect" url="http://{C:1}.bbb.com{PATH_INFO}" appendQueryString="true" />
</rule>

Azure Server Redirect module using get parameters

I try to make a permanent redirection on an azure website using the rewriting module using this pattern :
<rule name="Rewrite redirect-not-found-products-w" patternSyntax="ExactMatch" stopProcessing="true">
<match url="product/Product.aspx?product_id=287"/>
<action type="Redirect" url="https://example.com/product" redirectType="Permanent"/>
</rule>
But I would like take care of GET parameters
By example redirect :
example.com/product/Product.aspx?product_id=287
or
example.com/product/Product.aspx?product_id=35
to
example.com/product
but not the whole product/Product.aspx
Your rule should have condition with query string, you cannot use query string in match url=
<rule name="Rewrite redirect-not-found-products-w" stopProcessing="true">
<match url="^product/Product.aspx$" />
<conditions logicalGrouping="MatchAny">
<add input="{QUERY_STRING}" pattern="^product_id=287$" />
<add input="{QUERY_STRING}" pattern="^product_id=35$" />
</conditions>
<action type="Redirect" url="https://example.com/product" redirectType="Permanent" />
</rule>
Rule above will redirect:
example.com/product/Product.aspx?product_id=287
or
example.com/product/Product.aspx?product_id=35
to
example.com/product

IIS Rewrite pattern not working

I have a rewrite pattern that I can't get to work.
if someone goes to my site by using this url:
http://example.com/article/page/1?_escaped_fragment_=
I would like my rewrite pattern to match the querystring and then rewrite my path to
/snapshots/snapshot_article_page_1.html
I tried writing a rule like this:
<rule name="Seo rewrite rule" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" />
</conditions>
<action type="Rewrite" url="/assets/snapshots/snapshot__{REQUEST_URI}.html" appendQueryString="false" />
</rule>
But I just keep getting a 404 error (even though the page exists!). I even tried actually putting in the full URL to the page and it doesn't work, but if I put the URL in the browser, it shows it fine.
It appears I have done it.
The rule to match my example would be this:
<rule name="Seo rewrite rule" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)_escaped_fragment_=(.*)" />
</conditions>
<action type="Rewrite" url="/assets/snapshots/snapshot__{R:0}.html" appendQueryString="false" />
</rule>

Rewrite rule works in URLRewrite test window but not in my web.config

I have this rewrite rule that runs perfectly:
<rule name="Zona-Articulo" stopProcessing="true">
<match url="([_0-9a-z-]+)/([_0-9a-z-]+)/([0-9]+)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
</conditions>
<action type="Rewrite" url="?zona={R:1}&id={R:3}" />
</rule>
Sample URL:
www.domain.com/eshop/product-name-complete/1234
URL Rewrite:
www.domain.com/?zona=eshop&id=1234
So I need to convert from this pattern:
www.domain.com/eshop-product-1234
to this url:
www.domain.com/?zona=eshop&idpr=product-1234
I checked some helps and theoretically need to use this:
<rule name="tienda" patternSyntax="Wildcard" stopProcessing="true">
<match url="^eshop-([_0-9a-z-]+)" />
<conditions logicalGrouping="MatchAny">
</conditions>
<action type="Rewrite" url="?zona=eshop&idpr={R:1}" />
</rule>
In the URLRewrite test window it runs just fine, but in my web.config it doesn't rewrite.
What am I doing wrong?

IIS 7 URL Rewrite match for particular URL

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>

Resources