How to correctly setup Apache redirects for images

I’ve set up a reverse proxy from my Windows server to a blog hosted elsewhere. All is fine except for the sitemaps.

The blog is on a subdomain: http://blog.example.com
The proxied domain is https://example.com/blog

Read More

As I’m using WordPress, I’ve opted for Yoast SEO, but despite ARR doing the rerouting Google tools still complains about images it cannot access – on the origin domain. This is correct in one sense because I’ve added a second robots.txt on the subdomain, to stop duplicate content, but it doesn’t make sense, in the sense that Application Request Routing should be hiding the subdomain. However, we all know that Google does what it wants to do.

I’ve found some code which I’ve added to my htaccess file:

# WordPress SEO - XML Sitemap Rewrite Fix - for reverse proxy
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ https://example.com/blog/index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ https://example.com/blog/index.php?sitemap=$1&sitemap_n=$2 [L]
# END WordPress SEO - XML Sitemap Rewrite Fix

I’m not sure whether it’s doing anything at the moment because the image issue still exists, so my next step would be to try and redirect images to the new domain structure… and herein lies the problem – I know absolutely nothing about Apache stuff and definitely not apache rewriting.

What I need to do is redirect anything in the uploads folder, to a new absolute path

From, /wp-content/uploads/myimage.jpg to https://example.com/wp-content/uploads/myimage.jpg

Can anyone help with this final piece of the jigsaw?

Thanks in advance.

Related posts

1 comment

  1. You can probably use something like the following in your .htaccess:

    RewriteCond %{REQUEST_URI} ^/wp-content/uploads/
    RewriteRule ^(.*).(jpe?g|gif|png|bmp)$ https://example.com/wp-content/uploads/$1.$2 [NC,L,R=302]
    

Comments are closed.