IIS7 Url Rewrite module doesn't work - iis

I am tring set the rule as below:
<rewrite>
<rules>
<rule name="Test" stopProcessing="false">
<match url="abcd.com/admin(.*)" />
<action type="Redirect" url="xyz.com/admin{R:1}" logRewrittenUrl="true" />
<conditions trackAllCaptures="true">
</conditions>
</rule>
</rules>
</rewrite>
When I try to access to url:abcd.com/admin/login but action not work. Please help me about that. Thanks!

The match url does not contain the domain, so you need to remove that:
<match url="^admin(.*)" />

Related

IIS URL Rewrite remove part of path

After researching url rewrite and reviewing many posts, I'm still stumped as to why my url rewrite is not working. I am attempting to remove /carrot/ from the path.
Ex: https://my.server.com/carrot/mobile/path
should become: https://my.server.com/mobile/path
My URL rewrite rule is pretty simple and looks as follows:
<rule name="RemoveCarrotFromPath">
<match url=".*carrot(.*)" />
<action type="Rewrite" url="{R:1}" />
</rule>
All help is appreciated.
Edit Below you can find all rules in use in case this is an issue where various rules are clashing:
<rewrite>
<rules>
<rule name="redirectPayment" stopProcessing="true">
<match url="/payment" />
<action type="Redirect" url="https://my.app.com/carrot/Payment" />
</rule>
<rule name="redirectMembership" stopProcessing="true">
<match url="/membership" />
<action type="Redirect" url="https://my.app.com/carrot/Membership" />
</rule>
<rule name="RemoveCarrotFromPath">
<match url=".*carrot(.*)" />
<action type="Rewrite" url="{R:1}" />
</rule>
</rules>
</rewrite>
The solution to my issue was to use Redirect instead of Rewrite as follows:
<rule name="RemoveCarrotFromPath">
<match url=".*carrot(.*)" />
<action type="Redirect" url="{R:1}" />
</rule>

URL Rewrite Redirect

I dont understand writing URL Rewrite aspects yet. But need assistance as I dont know what I am doing incorrectly.
My goal is when a USER clicks on a link
www.example.com/NM/Registration?ctl=PasswordReset&resetToken=db08aa18-0810-417d-a633-131635bf9e8e
I would like the user to be redirected to
www.example.com/Registration?ctl=PasswordReset&resetToken=db08aa18-0810-417d-a633-131635bf9e8e
As you can see I would like to redirect without the NM in the URL path to the root domain.
I have this in my web.config file but it seems that it wont redirect properly:
<rewrite>
<rules>
<rule name="Query String Rewrite">
<match url="/NM/Registration" />
<conditions>
<add input="{QUERY_STRING}" pattern="ctl=([a-z]+)" />
<add input="##{C:1}##_{QUERY_STRING}" pattern="##([^#]+)##_.*resetToken=([_0-9a-z-]+)" />
</conditions>
<action type="Redirect" url="http://www.example.com/Registration?ctl={C:1}&resetToken={C:2}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
I figured out my answer. I ended up rewriting the rule so hopefully this will help out anyone in the future.
<rewrite>
<rules>
<rule name="Query String For Redirect">
<match url="NM/Registration" />
<conditions>
<add input="{QUERY_STRING}" pattern="ctl=([a-z]+)&resetToken=([_0-9a-z-]+)" />
</conditions>
<action type="Redirect" url="Registration?ctl={C:1}&resetToken={C:2}" appendQueryString="false" />
</rule>
</rules>
</rewrite>

URL Redirect web.config

I have the following URL
https://www.abcsite.com/?data=w35VTqIaVXWfi4GmESj8EGCG1cdF2aT%2BUF3D?utm_source=external%20system&utm_campaign=external%20system&utm_medium=EX.com&utm_content=MMB
which has extra ? at the end. which I Would like to remove and replace with "&"
I am using following rule but it is not working. can you review this and tell me what I am doing wrong.
<rewrite>
<rules>
<rule name="fixdata" stopProcessing="true">
<match url="\?(.*)\?(.*)$" ignoreCase="false" />
<action type="Redirect" redirectType="Permanent" url="http://www.example.com/{R:1}&{R:2}" />
</rule>
</rules>
</rewrite>
Thanks.
You rule should be like this:
<rule name="fixdata" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{QUERY_STRING}" pattern="(.*)\?utm_source(.*)$" />
</conditions>
<action type="Redirect" url="{R:0}?{C:1}&utm_source{C:2}" appendQueryString="False" />
</rule>
Your rule didnt work, because <match url= contains path without query string. You need to create additional condition to match query string with your regexp pattern

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.

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