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.
Related
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.
I'm working on updating the stripe checkout from a website, I was doing it successfully on localhost but when I put it on live mode on a windows server it stopped working. The issue is that when I should be redirected to the checkout page from stripe, the url is altered and becomes something that doesn't make sense:
The correct url: www.checkout.stripe.com/pay/cs_...
The url that I get redirected to: www.mysite.com/pay/cs_..
I kept thinking what could be the causa of that and I think it's the URL rewrite rule that I have on the windows server. I would like to add an exception to the rule and allow the stripe checkout to initiate, but I have no idea how to do it.
Below is my web.config file:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:8008/{R:1}" />
</rule>
<rule name="HTTPS" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I figured it out. This is my final web.config
<configuration>
<system.webServer>
<urlCompression doDynamicCompression="false" />
<rewrite>
<rules>
<clear />
<rule name="ReverseProxyInboundRule">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://localhost:8008/{R:1}" />
</rule>
<rule name="stripe redirect in checkout" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="/pay/" />
</conditions>
<action type="Redirect" url="checkout.stripe.com{REQUEST_URI}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
My issue was not really understanding the meaning of the options in the URL Rewrite. I checked the course URL Rewrite for Developers and it was really helpful. I was able to solve the issue quickly.
The file you have shown contains the inbound rewrite rules only. But you have an issue with response from your server. Thus, you should fix the outbound rewrite rule in the right config file.
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
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(.*)" />
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>