Template Redirect Function Only Working When Logged In

Based on what you provided, I agree with the comment from @vancoder that caching is likely at play here. If you’re not sure how to purge the caching on your site, the easiest approach may be to add a simple query string on the end of the original URL. That usually bypasses caching and loads the page from scratch.

So if your original URL was https://www.example.com/our-providers/, then while logged out, enter this in your browser and see if the redirect works: https://www.example.com/our-providers/?cache-test=123456789

Note that ?cache-test=123456789 is what’s added onto the end.

Also, manually setting up redirects through code can become cumbersome very quickly. I’d suggest one of two solutions here:

  1. Utilize a plugin that allows you to add redirects in the admin. My favorite is Redirection, but there are a lot out there.
  2. Check with your hosting provider to see if they offer a way to add redirects within their management tools. Most of the popular ones do.

Good luck!