0

My Wordpress environment is running on IIS/Azure. I have a web.config file that I need help with. I am already successfully permanently redirecting traffic from all URLs with a trailing slash to the same URL without that slash. Works great, except I need to negate this rule for one path so I don't break the wp-json (API) functionality supplied by Wordpress.

I took a stab at it, but this negate rule doesn't seem to work.

<rule name="Remove trailing slash" stopProcessing="true">
  <match url="(.*)/$" ignoreCase="true" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{REQUEST_URI}" negate="true" pattern="^\wp-json$" ignoreCase="true" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>

The URL I want exempt is still redirecting to a non trailing slash URL where in this case I need the trailing slash to remain.

DJ Monzyk
  • 48
  • 7

2 Answers2

0

I'm no regex guru, but maybe a negative look-ahead could help. I may not have the matching group correct, though.

^((?!wp-json\/).)*$

(Based on the discussion here: Regular expression to match a line that doesn't contain a word)

KirkF
  • 1
0

DJ,

I saw your add on UpWork and thought I'd give you something I found. They won't let me submit it in a proposal but I don't think it's right to charge for something until it's necessary.

I found this rule at (https://moz.com/community/q/web-config-redirects-not-working-where-a-trailing-slash-is-involved) and thought it might be what you're looking for. It should work with both a slash and without one.

<rule name="Test" stopProcessing="true">
    <match url="^example_folder" />
    <action type="Redirect" url="/newfolder" />
</rule>

If you still need help give me a shout and I'd be happy to look at it. My upwork profile is: https://www.upwork.com/fl/johns770?viewMode=1

John Swaringen
  • 731
  • 4
  • 11
  • 29