Scheduled PSN downtime tomorrow in Back Page News


3 replies to this topic - - - - -

#1 mikeaag

    Neowinian³

  • 283 posts
  • Joined: 30-May 09
  • Location: Essex

Posted 09 February 2012 - 14:32

Hey,

Im having some problems with a self hosted "CDN". Im using a wordpress plugin called W3 Total Cache to store images, css and js on a subdomain.

The problem is, some of the thumbnails that wordpress creates are not being uploaded to the cdn subdomain.

Is there anyway, using .htaccess, that i can redirect requests from cdn.mydomain.com/changing/path/to/image/picture.jpg to www.mydomain.com/changing/path/to/image/picture.jpg if that file does not exist on the cdn subdomain?

Thanks in advance

Mike


#2 firey

    Neowinian Wise One

  • 4,385 posts
  • Joined: 30-October 05
  • Location: Ontario, Canada
  • OS: Windows 7
  • Phone: Android (2.3.6)

Posted 09 February 2012 - 14:41

could probably do a custom 404 page, and just see where the user was trying to go (how they got to the 404) and just parse it, and if they are looking for an image, just do a header location. or an html re-direct.

#3 mikeaag

    Neowinian³

  • 283 posts
  • Joined: 30-May 09
  • Location: Essex

Posted 09 February 2012 - 16:31

Hi Firey,

Thanks for your reply.

Im not exactly sure what your suggesting there?

I basically just want it so that if the image doesnt exist on the subdomain it will still display the image from the origin domain.

I've been doing some googling and ive seen this example
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(jpg|gif|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*$ /no_picture.png [L]

but i dont really know how to alter this to suit my needs.

The request URL is going to be http://cdn.mydomain.co.uk/... and i need to change that to http://www.mydomain.co.uk/...

Thats the only part i want to change, i want the rest of the url to stay the same, as both domains have the same folder structure.

If someone could show me how to change this ,htaccess code, i would be very greatful.

In the mean time i'll keep googling the matter :D

Thanks in advance

#4 mikeaag

    Neowinian³

  • 283 posts
  • Joined: 30-May 09
  • Location: Essex

Posted 10 February 2012 - 11:19

Hey,

Just in case anyone else has a similar problem to me, ive found a workable solution based on the code i posted before.

I placed this code on cdn.mydomain.co.uk.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(jpg|gif|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . http://www.mydomain.co.uk/%{REQUEST_URI} [L]
</IfModule>

This basically means that if the CDN subdomain gets a request for an image file that it doesn't have, it redirects the request to the main domain (which does have the image).