• I’ve come accross a few different instances of the trailing slash rewrite which sometimes interferes with plugin REST APIs. I was wondering if there’s a one size fits all exclude for the wp-json folder.

    I struggle with REGEX so it would be a huge time saver.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    While WP will add a trailing slash to permalinks, it does not do so for API requests, so I’m unsure how this is happening. Stripping trailing slashes from non-API permalinks in .htaccess will not help much since WP will add them back afterwards. Not applicable to API requests anyway.

    I’m not exactly a regexp wiz either. I’ve found regexr.com helpful in composing and testing my regexp.

    This .htaccess directive may not help since I don’t know how trailing slashes are added to start with, but to remove them, something like this:
    RedirectMatch 302 (wp-json/.*)/$ $1 [L]
    (untested) Also unsure if it’s better near the top or near the bottom of .htaccess.

    • This reply was modified 3 years, 6 months ago by bcworkz. Reason: forgot the wp-json
    Thread Starter Nigel M Rodgers

    (@rodgersnigel)

    Thanks for the explanation. It really helped me understand.

    I get support requests where the wp-json path is broken. Usually it’s WordFence, Cloudflare or some other security firewall, but every once a week or so it’s an htaccess-added trailing slash.

    I’ll try your snippet next time I come accross a similar issue. Looks like it will work!

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘htaccess exclude wp-json from trailing slash rewrites’ is closed to new replies.