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