wordpresscdnamazon-cloudfrontw3-total-cache

CDN Pathing to Source Incorrect


I set up W3 Total Cache to link up to my Amazon CloudFront CDN. Some links work properly, but not for all links on my websites. Below is an example of a JS file that is outputted the problematic link I'm having.

  <script src="<?php echo get_template_directory_uri(); ?>/_js/libs/picturefill.js" async="true"></script>

CSS uses the same format as the line of code above. Some of the links for images provided by the client making a custom post inside the WP CMS itself work but some don't give a proper link either.

This is an example of the problematic pathing link.

http://cdn.example.com/example.com/mydirectory/wp-content/themes/mytheme/...

It should simply be:

http://cdn.example.com/mydirectory/wp-content/themes/mytheme/...

There isn't any other code that points towards this error. The only other thing I can think of causing this problem is a cacheing issue but I don't know what cache this is coming from.

Edit 1: Clarification.


Solution

  • I figured out the solution to this problem. I was setting my WP_HOME and WP_SITEURL in my wp-config file. W3TC prepends this with my CNAME for my CDN. However, I already had example.com prefixed before my subdirectories. Therefore, that's where I was getting cdn.example.com/example.com. After I removed example.com from WP_HOME and WP_SITEURL to not be absolute pathing but relative, it all worked.