Cache busting URL rewrite won't work on cloudflare

What is the name of the domain?

What is the error number?

404

What is the error message?

404 errors

What is the issue you’re encountering

Not loading our custom URLs

What steps have you taken to resolve the issue?

We use a custom URL system in our website, which helps us to make sure people are using the latest version of files. For example:
/2018/v97/css/home_new.css

All this does is rewrite using nginx to /2018/css/home_new.css

That allows us to increase the number vXX when we make major changes , to make sure they are using the latest. Unfortunatly, cloudflare seems to do some weird stuff with those URLs - giving us a 404

What are the steps to reproduce the issue?

I’ve had to take the site off Cloudflare, as the whole site was broken (no CSS, JS etc). So to test this - you need to add this to your hosts file:

172.67.146.66

Then, access:

https://www.chambresdhotes.org/2018/v97/css/home_new.css

You should see a 404 error. The URL is actually:

https://www.chambresdhotes.org/2018/css/home_new.css

However, we use an nginx rule to

  location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js|eot|otf|ttf|woff|woff2|map)$ {

        rewrite "/(\d+)/v\d+/js/(.+)\.js$" /$1/js/$2.js last;
        rewrite "/(\d+)/v\d+/css/(.+)\.css$" /$1/css/$2.css last;
        rewrite "/(\d+)/v\d+/css/(.+)$" /$1/css/$2 last;

        rewrite "/(\d+)/v\d+/js/(.+)\.js.map$" /$1/js/$2.js.map last;
        rewrite "/(\d+)/v\d+/css/(.+)\.css.map$" /$1/css/$2.css.map last;
        rewrite "/(\d+)/v\d+/css/(.+)/(.+)\.css.map$" /$1/css/$2/$3.css.map last;

 }

I’m really not sure what else to try. As I said, it all works fine when not using cloudflare - so I’m guessing its doing something with the URLs (I’m just not sure what!)

Thanks in advance

Andy

Hi Andy,

When your nginx makes changes to the content, are you actively purging Cloudflare cache?

If you set Cloudflare to not cache content, and send the request straight to Origin, are you still seeing the 404s?

Thank you.

Hi

The only way I could get it to work, was by setting up a rule:

I’m still not sure why it wasn’t working (if I took the site off cloudflare, it worked perfectly, and as soon as it was back on cloudflare, even in “dev mode”, it would give 404s for those files).

Cheers

Andy

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.