2

I've got some IIS rewrite rules in place, and everything is working fine. But i feel like i can consolidate them.

Here are my rules:

<rule name="Blog - Advice - root" patternSyntax="ExactMatch" stopProcessing="true">
    <match url="advice" />
    <action type="Rewrite" url="https://mysite.wpengine.com/advice" />
</rule>

<rule name="Blog - Advice - root (with slash)" patternSyntax="ExactMatch" stopProcessing="true">
    <match url="advice/" />
    <action type="Rewrite" url="https://mysite.wpengine.com/advice" />
</rule>

<rule name="Blog - Advice" stopProcessing="true">
    <match url="^advice/?(.*)" />
    <action type="Rewrite" url="https://mysite.wpengine.com/advice/{R:1}" />
</rule>

I want to match the following examples:

  • /advice
  • /advice/ (should rewrite without the slash)
  • /advice/sdfsdf
  • /advice/sdfsdf/ (should rewrite without the slash)
  • /advice/sdfdsf/sdfds

Can it be done with 1 (or 2) routes?

If i leave the second one out for example, Wordpress (the site i'm rewriting to), will do a 301 redirect to a URL without the slash, and i lose the rewrite since the URL is changed again. (so i end up at mysite.wpengine.com/advice, which is wrong).

So i need to make sure any rewrites don't involve a redirect on the target site end.

Many thanks :)

RPM1984
  • 72,246
  • 58
  • 225
  • 350

0 Answers0