Preventing Canonical Redirect for CDN


I want to run my entire WordPress site through a CDN to improve performance (HTML, not just static CSS/JS/media). Lets say the origin server is and is the URL where traffic will go through the CDN set-up as an origin-pull.

The problem is an infinite loop will be created when visiting which passes the request to WordPress which will look at the request and say “Actually this should be according to the home_url and site_url defined in the Settings” Sooo…

1) Is there an easy way make WordPress stop redirecting to www under a certain condition (like checking for the x-forwarded-for headers which will be added to requests coming through the CDN)?

2) Am I going to have to set a constant to change the site URL for requests from the CDN and then set-up some sort of output buffering callback to replace to ?

I know there are plugins out there that handle this. I’m looking to roll my own so I can figure out how this all works. Any guidance would be much appreciated.

, , , kingkool68 3 years 2020-05-30T09:10:24-05:00 0 Answers 96 views 0

Leave an answer