Add exception to url rewrite for a particular external domain

Ana Cláudia Faria 1 Reputation point
2022-05-13T15:15:37.507+00:00

Hello,
I'm hosting a website on a windows server and below is my webserver configuration.
There's an issue when my website tries do redirect to the stripe checkout page, since the url that should be www.checkout.stripe.com/pay/cs\_... becomes www.mysite.com/pay/cs\_... which I suspect is because of the rule below.
Is there anyway that I can add an exception to this rule and allow www.checkout.stripe.com to not be redirected?
If that is no possibility, is there a chance that when I get redirected to the checkout I can add text before mysite url? This is because stripe allows me to do checkout with a custom domain and maybe I could do checkout.mysite.com if the first option is not possible.

I'm quite new to this so any help is much appreciated.

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:8008/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Thank you

Windows development Internet Information Services
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sam Wu-MSFT 7,561 Reputation points Microsoft External Staff
    2022-05-16T01:38:11.117+00:00

    @Ana Cláudia Faria

    There's an issue when my website tries do redirect to the stripe checkout page, since the url that should be www.checkout.stripe.com/pay/cs\_... becomes www.mysite.com/pay/cs\_... which I suspect is because of the rule below.

    <rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <action type="Rewrite" url="http://localhost:8008/{R:1}" />
    </rule>

    This rule does not cause www.checkout.stripe.com/pay/cs\_... to become www.mysite.com/pay/cs\_..., If it works, it should redirect to http://localhost:8008/pay/cs_...

    Is there anyway that I can add an exception to this rule and allow www.checkout.stripe.com to not be redirected?

    If you want it not to be redirected when the hostname is checkout.mysite.com, you can add the following condition to the rule, negate this condition with the negate attribute.

    <conditions logicalGrouping="MatchAny">  
         <add input="{HTTP_HOST}" pattern="^checkout.mysite.com$" negate="true" />  
    </conditions>  
    

    Finally I suggest you to use failed request tracing to see the process in detail so you will find out what the problem is.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Ana Cláudia Faria 1 Reputation point
    2022-05-20T09:36:46.8+00:00

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.