question

AnaCludiaFaria-0992 avatar image
0 Votes"
AnaCludiaFaria-0992 asked AnaCludiaFaria-0992 published

Add exception to url rewrite for a particular external domain


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-server-iis
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SamWu-MSFT avatar image
0 Votes"
SamWu-MSFT answered SamWu-MSFT commented

@AnaCludiaFaria-0992

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SamWu-MSFT thanks for your input. Yes, it redirects to localhost:8008/pay/cs_... but won't that translate to mysite.com/pay/cs_..., I'm hosting a nodejs website on my windows server and I think that's the way he can connect my domain to the server.
Ideally I want to not be redirected when the url is checkout.stripe.com/pay/cs_... is that possible?
The idea of having the possibility of checkout.mysite.com/pay/cs_... would be an alternative as it has extra fees to add that url from stripe. Thank you

0 Votes 0 ·
SamWu-MSFT avatar image SamWu-MSFT AnaCludiaFaria-0992 ·

@@AnaCludiaFaria-0992

Ideally I want to not be redirected when the url is checkout.stripe.com/pay/cs_... is that possible?

My answer above will slove this question, you can add a rule that matches checkout.stripe.com/pay/cs_... to the condition, and then use the negation attribute to negate it(when this attribute is used, the rule action is performed only if the current URL does not match the specified pattern.), so that when the requested url is checkout.stripe.com/pay/cs_... , it will not be redirected.

 <conditions logicalGrouping="MatchAny">
       <add input="{HTTP_HOST}" pattern="^checkout.mysite.com$" negate="true" />
       <add input="{REQUEST_URI}" pattern="^pay/cs_...$" negate="true"  />
  </conditions>
0 Votes 0 ·
AnaCludiaFaria-0992 avatar image
0 Votes"
AnaCludiaFaria-0992 answered AnaCludiaFaria-0992 published

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.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.