IIS rewrite still active eventhough it is disabled - iis

I have this iis site for which I have added some rewrite rules.
The rewrite rule itself is simple If I access the site www.a.com rewrite/redirect to www.b.com
and redirect subpages to corresponding subpages on www.b.com
So have via IIS manager setup some rewrite rules.
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match l=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" l="https://{HTTP_HOST}{REQUEST_I}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="https://shop.a.com/5e/ -> https://www.b.com/products/5/" enabled="true" patternSyntax="ExactMatch" stopProcessing="true">
<match l="https://shop.a.com/5e/" />
<action type="Redirect" l="https://www.b.com/products/5/" logRewrittenl="false" />
</rule>
<rule name="https://shop.a.com/5e/ -> https://www.b.com/products/5/" enabled="true" patternSyntax="ExactMatch" stopProcessing="true">
<match l="https://shop.a.com/5e/" />
<action type="Redirect" l="https://www.b.com/products/5/" logRewrittenl="false" />
</rule>
<rule name="https://shop.a.com/10e/ -> https://www.b.com/products/10/" enabled="false" patternSyntax="ExactMatch" stopProcessing="true">
<match l="https://shop.a.com/10e/" />
<action type="Redirect" l="https://www.b.com/products/10/" logRewrittenl="true" />
</rule>
<rule name="https://shop.a.com/16e/ -> https://www.b.com/products/16/" enabled="false" patternSyntax="ExactMatch" stopProcessing="true">
<match l="https://shop.a.com/16e/" />
<action type="Redirect" l="https://www.b.com/products/16/" logRewrittenl="true" />
</rule>
<rule name="https://shop.a.com/3e/ -> https://www.b.com/products/3/" enabled="false" patternSyntax="ExactMatch" stopProcessing="true">
<match l="https://shop.a.com/3e/" />
<action type="Redirect" l="https://www.b.com/products/3/" logRewrittenl="true" />
</rule>
</rules>
</rewrite>
prior to this I had a rewrite that rewrote shop.a.com to www.b.com
This one should not be active anymore, but for somereason is this still active, and all the other rules listed here does not seem to work.
When I access shop.a.com/5e I enter www.b.com.
The network tab in chrome states that the url is being redirected to www.b.com, but have no idea where this redirect is listed if not in the web.config?
the url mentioned here are only examples and not the actual sites being managed.
Any idea on why this redirect is doing this?

I used regex match instead which made it work.
The exact matching via iis did not work as expected.

Related

How to write rules under URL redirect in IIS 10

I want to write redirect rules in IIS 10. I googled it but could not found proper solution.
I have added some more scenarios.
https://testing.app.com/apptest should redirect to https://testing.app.com/apptest/account/login
https://testing.app.com/apptest/ should redirect to https://testing.app.com/apptest/account/login
https://test-apptest.testing.app.com/ should redirect to https://test-apptest.testing.app.com/account/login
https://test-apptest.testing.app.com should redirect to https://test-apptest.testing.app.com/account/login
Appreciated if someone can please help me with this.
What I tried so far is:
<rewrite>
<rules>
<rule name="Test1" stopProcessing="true">
<match url="apptest/login" />
<action type="None" />
</rule>
<rule name="login">
<match url="^apptest" />
<action type="Redirect" url="testing.app.com/apptest/login" appendQueryString="false" />
</rule>
</rules>
</rewrite>
You can try the rule below:
<rule name="test5" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="testing.app.com" />
<add input="{REQUEST_URI}" pattern="^/apptest$" />
</conditions>
<action type="Redirect" url="https://www.google.com/" appendQueryString="false" />
</rule>

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 Web App URL Rewrite not working

I'm trying to get a basic URL rewrite to work for my Azure web App
<system.webServer>
<rewrite>
<rules>
<rule name="SalesCloudGmail" stopProcessing="true">
<match url="/SalesCloudGmail.aspx" />
<action type="Redirect" url="/SalesCloudGmail" />
</rule>
</rules>
</rewrite>
</system.webServer>
Was expecting to open the URL .../SalesCloudGmail.aspx and see .../SalesCloudGmail in the Address bar???
What Am I missing
Give this a try, your regex pattern matching is a little off based on how you're using it. But this should work or at least get you much closer.
<rule name="SalesCloudGmail" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^\/SalesCloudGmail\.aspx.*" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/SalesCloudGmail" />
</rule>
Please try below rewrite rule:
<rewrite>
<rules>
<rule name="SalesCloudGmail" stopProcessing="true">
<match url="^\/SalesCloudGmail\.aspx$" />
<action type="Redirect" url="/SalesCloudGmail" />
</rule>
</rules>
</rewrite>
Please following this article to test your match pattern.

IIS rewrite change filename

I have some old URLs in a forum application points to http://mydomain.tld/showthread.php?p=xxxx where xxxx is the an integer id.
My new forum application uses viewtopic.php?p=xxxx and I want to handle this using IIS web.config rewrite rules.
I have tried to add the last rule as the following:
<rewrite>
<rules>
<rule name="Redirect www to non www" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<action type="Redirect" url="http://domain.tld/{R:1}" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.tld" negate="true" />
</conditions>
</rule>
<!-- this for change from showthread.php to viewtopic.php -->
<rule name="Rewrite" stopProcessing="true">
<match url="(.*)showthread\.php" />
<action type="Rewrite" url="viewtopic\.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
However, it does not able to redirect to the viewtopic.php. Any suggestion?
I have to enable httpRedirect in the IIS. Then I used this redirect rule in the web.config at the root of my forum:
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="*showthread.php" destination="/viewtopic.php?$P" />
</httpRedirect>

How to append query string & value via IIS rewrite rule?

I'm running IIS 7 with the offical rewrite rule module installed. I'd like to create a rewrite rule to match this URL:
http://www.sample.com/en-us/test.aspx?q=keyword
After rewriting the expected result would be:
http://www.sample.com/en-us/test.aspx?q=keyword&flag=value
How can I create a rule to implement this?
I've tested the following rule, but no luck, it always got redirect loop error:
<rewrite>
<rules>
<rule name="test" stopProcessing="true">
<match url="(.*)/test\.aspx(.(?!flag=value))*$" />
<action type="Redirect" url="{R:0}&flag=value" appendQueryString="false" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
Found the solution by myself, just share it.
<rewrite>
<rules>
<rule name="Redirect for download result page" stopProcessing="true">
<match url="(.*)/test.aspx(.*)" />
<action type="Redirect" url="{R:1}/test.aspx?rf=sp" appendQueryString="true" redirectType="Found" />
<conditions>
<add input="{QUERY_STRING}" pattern="flag=value" negate="true" />
</conditions>
</rule>
</rules>
</rewrite>

Resources