• 0

If image doesnt exist on subdomain, redirect it to different domain


Question

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

3 answers to this question

Recommended Posts

  • 0

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.

  • 0

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]
[/CODE]

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

  • 0

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>
[/CODE]

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).

This topic is now closed to further replies.
  • Posts

    • Did you go into settings > engines and switch some more stuff on. The more you enable the slower it will get but the better the results will be
    • SpaceX took its largest step yet toward becoming a retail wireless carrier on Friday when President and COO Gwynne Shotwell told investors at the company's IPO roadshow that SpaceX is considering launching a Starlink-branded mobile phone service for US consumers.............. https://www.techtimes.com/articles/319177/20260627/starlink-mobile-coming-t-verizon-spacex-has-spectrum-still-needs-towers.htm  
    • Stop asking people that. It's a "No True Scotsman" argument in that you are attempting to discredit the opinions of a person by Attacking the Messenger. The reason that these are logical fallacies is the TRUTH is based on facts as supported by evidence. Nothing else. So, always debate the facts with evidence to reach the truth. Once you learn to do this, you'll be able to recognize when people are fearmongering and lying to you for their own selfish ends.
    • It doesn't matter if you didn't directly hear it from person X or Y. Every one of your statements comes straight from the racist, skinhead, anti-immigrant, be afraid of everything, "they are all taking our jobs", etc. etc. mouthpieces. That's where Farag and Putin heard it from too...and used it against the UK. So, while you keep disavowing the people who publicly peddled that position, you keep proving over and over again that those lies influenced you into being tricked when the Brexit vote came around too. In fact, your final sentence makes it crystal clear that it was the racist/anti-immigrant lies you fell and voted for, since you stated that you didn't have an issue with the economic trade issues with the EU. Ahem. To be clear, all of these LIES are EONS old, mate. They are the same fearmongering lies peddled to the same ignorant, gullible cowards by the same charlatans, snake-oil salesmen, and would be demagogues who've been doing this since caveman Ugh lied about his slightly different neighbor in order to steal his land. And, finally, you answered your own previous question. The reason that the EU isn't clamoring to bring the UK back is that they have had enough of people who would rather shoot themselves in the foot than get over their "insecurity issues". It's the same reason the entire world is moving away from the USA as fast as it can...
  • Recent Achievements

    • Week One Done
      flexorcist earned a badge
      Week One Done
    • One Month Later
      Woland13 earned a badge
      One Month Later
    • Week One Done
      Woland13 earned a badge
      Week One Done
    • One Year In
      bernmeister earned a badge
      One Year In
    • Week One Done
      Scoobystu earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      498
    2. 2
      +Edouard
      222
    3. 3
      PsYcHoKiLLa
      148
    4. 4
      Steven P.
      74
    5. 5
      FloatingFatMan
      69
  • Tell a friend

    Love Neowin? Tell a friend!