2

Im sure there must be a clever way round this but I just cant figure it out. I am using mod_rewrite to create SEO friendly filenames AND switch to our CDN. I can do them both seperately but together they cancel eachother out

We use mod_rewrite (in htaccess) to create SEO friendly filenames. So for example :-

RewriteRule ^thumbnails/([0-9]+)/([^/]+).jpg$ /thumbnails/$1/image.jpg [NC,L]

maps https://www.example.com/thumbnails/123/my-image-of-a-puppy.jpg onto https://www.example.com/thumbnails/123/image.jpg

That all works fine. But we also use mod_rewrite to pull the images from the CDN so we use something like this :-

RewriteRule ^(.*).(jpeg|jpg|png)$ https://cdn-w.example.com%{REQUEST_URI} [R=301,NC,QSA,L]

Now mod_rewrite does an external 301 redirect (or 302 if i leave out the R=301 bit).

That all works fine too but as far as google is concerned, https://www.example.com/thumbnails/123/my-image-of-a-puppy.jpg simply gets redirected to https://cdn-w.example.com/thumbnails/123/image.jpg which cancels out the SEO friendly filename doesnt it ??

Am I missing something ?

1 Answers1

0

If you use the [P] modifier on the CDN reference it should work as you intend.

Use this flag to achieve a more powerful implementation of the ProxyPass directive, to map remote content into the namespace of the local server.

So the URL should stay the same as it is on the way in, with the content from the CDN.

Mod Proxy

Aidan
  • 757
  • 3
  • 13
  • One of the main points of using a CDN, is probably that you want to take load of your server. If you now make your server act as proxy, so that every request for any of those CDN resources has to “go through” it again, that kinda negates that point completely. And the time frame until the user finally gets the data, will probably also be increased. – 04FS Jan 21 '20 at 07:54