简体   繁体   English

W3总缓存插件CDN网址不适用于woo主题

[英]W3 total cache plugin cdn url not working with woo theme

I am currently trying to get W3 Total Cache to work on a wordpress website and noticed some rather weird behavior with the CDN url request being sent. 我目前正在尝试使W3 Total Cache在wordpress网站上工作,并且注意到CDN url请求被发送时出现了一些相当奇怪的行为。

I am using cloudfront cdn and point it to CNAME (cdn.test.com) pointing to the cloudfront url. 我正在使用cloudfront cdn并将其指向指向Cloudfront URL的CNAME(cdn.test.com)。

Now all the images, css and javascript that are not part of the theme are rendering properly with the CDN CNAME url. 现在,所有不属于主题的图像,css和javascript都可以使用CDN CNAME url正确呈现。

example: http://cdn.test.com/wp-content/2015/01/image-150X150.jpg
http://cdn.test.com/wp-includes/base/css/style.css
http://cdn.tes.com/wp-includes/base/js/home.js

(May I also add that this also happens with the cloudfront url as well.) But when it come to the css and javascript that are part of the woo theme it renders as follows. (我还可以补充一点,这也是cloudfront URL也会发生的。)但是,当涉及到woo主题的css和javascript时,它呈现如下。

http://cdn.test.com/http://example.com/wp-content/themes/test-theme/js/theme.js
http://cdn.test.com/http://example.com/wp-content/themes/test-theme/css/theme.css

I have taken this up with the theme developers and others concerned but very little has come out from them. 我已经与主题开发人员和其他相关人员进行了交流,但是他们很少提出建议。

I have looked at various options like using preg_replace to match the occurrence of the weird url and replace it with an empty string. 我已经看过各种选项,例如使用preg_replace匹配出现的怪异url并将其替换为空字符串。

This however did not work because i was probably using/calling the wrong add_action or add_filter from the reference documentation https://support.woothemes.com/hc/en-us/articles/203106877-Canvas-Hook-Filter-Reference and that of wordpress (I mean wp_head or wp_footer). 但是,这不起作用,因为我可能使用/调用了参考文档https://support.woothemes.com/hc/en-us/articles/203106877-Canvas-Hook-Filter-Reference中的错误的add_action或add_filter,的wordpress(我的意思是wp_head或wp_footer)。

As you may have figured out I am not experienced with wordpress and I ask that you please help explain what is going on or wrong with this and possible ways i can resolve this matter. 正如您可能已经知道的那样,我没有Wordpress的经验,请您帮忙解释一下发生了什么问题或问题以及我可以解决此问题的可能方法。

Thanks for your help. 谢谢你的帮助。

Finally, traced and fix this issue with this code: 最后,使用以下代码跟踪并解决此问题:

add_filter('w3tc_cdn_url', 'fix_host_in_cdn_url',10,3);
function fix_host_in_cdn_url($content) {
  $content = preg_replace("/(\/http?:\/\/[\da-z\.-])/", '', $content);
  return $content;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM