admin管理员组文章数量:1335436
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 example and www.example 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 www.example which passes the request to WordPress which will look at the request and say "Actually this should be www.example 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.
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 example and www.example 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 www.example which passes the request to WordPress which will look at the request and say "Actually this should be www.example 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 http://example to http://www.example ?
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.
Share Improve this question asked Nov 6, 2013 at 23:15 kingkool68kingkool68 1,2191 gold badge11 silver badges24 bronze badges3 Answers
Reset to default 1This can not work in the way you want. If wordpress is on example then all the auto generated links will point to example even for pages that are on the CDN under the www.example domain. This will result that after the first page being served from the CDN many other pages will be served directly from wordpress.
from inspecting the code, the code that does it is deep inside
redirect_canonical
so either you need to write your own redicrection and do something likeremove_action("template_redirect", "redirect_canonical");
add_action('template_redirect', 'wpsr12150_redirect_canonical');
function wpsr12150_redirect_canonical() { // code without the www redirection }
but it is probably easier to handle it in an .htaccess file, for example make it always remove the www from incoming requests
- yes!
I did manage to get this to work. Here are the details of what I did in case you want to do the same thing: https://gist.github/kingkool68/7421460
After two days searching I've finally found the answer for my problem
// disable WordPress's Canonical URL Redirect feature remove_filter('template_redirect','redirect_canonical');
from https://taylor.callsen.me/settings-up-aws-cloudfront-in-front-of-wordpress/
本文标签: urlsPreventing Canonical Redirect for CDN
版权声明:本文标题:urls - Preventing Canonical Redirect for CDN 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742387676a2465360.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论