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:


To be redirected to:


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:


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, 2017 at 11:36

1 Answer 1


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 and acknowledge you have read our privacy policy.

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