• Resolved nikdow

    (@nikdow)


    Since about 12 hours ago the site stopped loading CDN assets.
    CDN is https://cdn.spelfabet.com.au which is an AWS Cloudfront endpoint.
    In /wp-admin I clicked on Save Changes and Validate Configuration button and this reports
    Invalid CDN Hostname: cdn.spelfabet.com.au returned a 301 status code.
    The plugin then shuts down so the site is now fixed because the CDN is not active.
    Here is an example of a CSS file:
    https://cdn.spelfabet.com.au/wp-content/plugins/cdn-enabler/css/settings.min.css?ver=2.0.0
    This address loads OK if I paste it into the address bar of a browser.
    So I’m not able to figure out why cdn-enabler is seeing a 301 from Cloudfront.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Anonymous User 16850768

    (@anonymized-16850768)

    This could be occurring due to how the validation request URL is being generated in version 2.0.0. This will be updated in the next release (version 2.0.1) as it wasn’t working for all installation types. Please let me know if it still occurs after the next update. As for now the configuration validation can be skipped if you’d like by just clicking the “Save Changes” button instead.

    Thread Starter nikdow

    (@nikdow)

    Thanks for quick answer.

    I’ve saved without validation (TBH I had ignored that button, thanks for pointing it out).
    This allows me to see the problem. The CDN appears to have changed behaviour and is substituting the Domain Name not only at the start of the link but also within the link. Due to the way our server is set up (our own version of a network WordPress install where everything except /uploads is owned by root), we interpolate the domain name within the URL. Prior to your version 2.0.0 this didn’t cause a problem because the cdn-enabler only substituted the domain name part of the URL. It is now substituting that domain name everywhere in the link.
    So where we have a link such as:
    https://www.spelfabet.com.au/wp-content/www.spelfabet.com.au/plugins/jetpack/css/jetpack.css?ver=9.4
    cdn-enabler is now recoding that as
    https://cdn.spelfabet.com.au/wp-content/cdn.spelfabet.com.au/plugins/jetpack/css/jetpack.css?ver=9.4
    Cloudfront receives the request and attempts to get the file from
    https://www.spelfabet.com.au/wp-content/cdn.spelfabet.com.au/plugins/jetpack/css/jetpack.css?ver=9.4
    which breaks on our server.
    For now I’ve added another rewrite rule to the apache <virtualhost> for that domain which fixes the problem, but if possible I’d suggest you revert the text substitution of links to only change the domain name part.
    Added rule:
    RewriteRule ^/wp-content/cdn.spelfabet.com.au/(.*) /wp-content/%{SERVER_NAME}/$1 [L]

    Thread Starter nikdow

    (@nikdow)

    The old code (pre 2.0.0) had the rewrite thus:
    $urls_regex = ‘#[^\”\’\s=>(,]+(‘ . $included_file_extensions_regex . ‘)(?=\/?[?\\\”\’\s)>])#i’;

    $rewritten_contents = preg_replace_callback( $urls_regex, ‘self::rewrite_url’, $contents );

    return $rewritten_contents;

    This has been replaced by a simple
    if ( stripos( $file_url, ‘/’ . $site_hostname ) !== false ) {
    return str_replace( $site_hostname, $cdn_hostname, $file_url );
    }

    Anonymous User 16850768

    (@anonymized-16850768)

    You’re most welcome! Ah, you’re right. In version 2.0.0 if the site hostname occurs more than once in a URL, like the example you’ve provided, all occurrences will be rewritten to use the CDN hostname. I know why this is occurring and will fix this. (All of the code you’ve copied is from version 2.0.0.)

    Thread Starter nikdow

    (@nikdow)

    Thanks, appreciate the free plugin which has been running very well for a long time, and makes the site faster and saves load on our server.

    Anonymous User 16850768

    (@anonymized-16850768)

    You’re welcome, @nikdow. I’m really happy to hear that. Version 2.0.2 fixed this issue. I’d love to get your feedback to confirm that.

    Thread Starter nikdow

    (@nikdow)

    Yes it is fixed! Thanks very much. I’m now seeing requests like this again:
    Request URL: https://cdn.spelfabet.com.au/wp-content/www.spelfabet.com.au/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js?ver=5.0.0
    I’ve commented out the additional apache rewrite config that was working around the issue.
    Thanks for the fast fix.

    Anonymous User 16850768

    (@anonymized-16850768)

    Excellent! Thank you for the confirmation. I’m really happy to hear that. If you haven’t already and are able leaving a review is always appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘cloudfront 301 status’ is closed to new replies.