0

Previously I've been using domain sharding to serve images from a cookieless domain. I've changed all the paths from domain.com/wp-content/uploads/* to /media/ with the following htaccess-rule:

RedirectMatch 301 ^/wp-content/uploads/(.*)$ https://media.domain.com/$1

This resulted in the following link:

https://www.domain.com/wp-content/uploads/2017/08/image.jpeg

To be redirected to:

https://media.domain.com/2017/08/image.jpeg

Yesterday I made my switch to HTTP/2, which makes 'domain sharding' not necesary. So this time around, I want to do the oposite switch, switching from media.domain.com to domain.com/wp-content/uploads. I've tried this by placing the following in the htaccess-file:

RedirectMatch 301 ^(.*)$ https://www.domain.com/wp-content/uploads$1

However, this results in an infinite loop:

https://www.domain.com/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/wp-content/uploads/2017/08/image.jpeg

What am I doing wrong here?

Edit: It is good to know that 'media' is a subdomain that is placed in the 'public_html' directory of the main website. So public_html is the main website and public_html/media is the media folder. The htaccess is placed in public_html

  • "...to /media/ with the following htaccess-rule:" - The redirect is mostly superfluous (unless you specifically had a lot of images indexed by search engines or linked to directly by third parties?!). Unless you had physically changed the image URL to media.example.com in your application then you won't have benefited from "domain sharding" - in fact, if this was only implemented with a redirect (which you seem to imply) then this would have been bad for users, your server (and potentially SEO)? – MrWhite Sep 15 '17 at 11:36
0

Fixed it by placing the htaccess with the rule in the media-folder, instead of public_html. Silly me. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.