URL Rewrite Redirect - iis

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>

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>

How to create a rewriteMap in IIS with dynamic path?

I'm trying to make a rewrite map in IIS to rewrite any call from domain.com/v/{PATH} to domain.com/api/v/{PATH} as i've changed my hosting logic and as an external service can't change the .GET request is making to domain.com/v/{PATH} in domain.com/api/v/{PATH} i have to rewrite any call in IIS..
I've created the following rewriteMap:
<rewrite>
<rewriteMaps>
<rewriteMap name="vmenuAuth">
<add key="/v/" value="/api/v/" />
</rewriteMap>
</rewriteMaps>
<rules>
<rule name="Regola di reindirizzamento1 per vmenuAuth">
<match url=".*" />
<conditions>
<add input="{vmenuAuth:{REQUEST_URI}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
But it works only if the url has ONLY the /v/ so if i write domain.com/v/ it rewrite the url to domain.com/api/v/ but if i try to add the path domain.com/v/VHGbrbfFHHTRfbFKSZ it will still remain the same without redirecting the user to domain.com/api/v/VHGbrbfFHHTRfbFKSZ
It seems that it is unnecessary to apply the URL Rewrite Maps under the circumstance.
We will redirect the URL to the new path as long as we match the “/v/” segment, is it right?
Please refer to the below configuration.
<rewrite>
<rules>
<rule name="abc" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{Request_URI}" pattern="/v(.*)" />
</conditions>
<action type="Redirect" url="/api/v{C:1}" appendQueryString="false" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MyMap" defaultValue="">
<add key="1234" value="HtmlPage1.html"></add>
</rewriteMap>
</rewriteMaps>
</rewrite>
Feel free to let me know if there is anything I can help with.

IIS - Redirect to subfolder with mask

I'm using IIS 10. I've a website that is reachable with subdomain1.domain.com and subdomain2.domain.com only on HTTPS protocol.
I would like to set up a rewrite rule only if request comes from subdomain2.domain.com where website should load the URL subdomain2.domain.com/la/signin. This last URL should be masked and not showed to the user.
I've tried a lot of rewrite rules and searched other suggestions on stackoverflow but every solutions did not worked for me, even without mask.
This one is just my last try without mask, but I've tried many other solutions:
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="https://subdomain2\.domain\.com$" />
<action type="Rewrite" url="{R:0}/la/signin" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
Any other suggestion?
Please try this rule. It will rewrite https://subdomain2.domain.com(/) to subdomain2.domain.com/la/signin.
<rule name="Redirect" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="la/signin" appendQueryString="true" logRewrittenUrl="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="subdomain2\.domain\.com" />
<add input="{HTTPS}" pattern="^on$" />
<add input="{URL}" pattern="^(/)?$" />
</conditions>
</rule>

IIS7 Url Rewrite module doesn't work

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(.*)" />

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