Hugo doesn’t do any rewriting of URLs. It’s beyond the scope of what Hugo server is designed to do. If you want this functionality use something like Nginx or Caddy in front of Hugo.
First, Hugo doesn’t support that. My suggestion would be to move your images into the static/images/ folder of your Hugo project, remove the mod_rewrite junk from apache, and be done with it. You may want to reverse the rewrite logic for a spell so that all the search engines can update to the new location, and then remove the rewrite rules.
Second, I’m really curious why in the world you would want to do such a thing in the first place. You’re basically forcing two HTTP requests for every image on your site, which wastes bandwidth and creates latency.
Maybe create a config variable to contain either ‘/images/’ or ‘http://b.robnugen.com/’, and change it as necessary depending on whether you’re working locally or deploying?
@thunderrabbit A little curious as to why you’re doing this, but here are a few ideas:
Prepend the full URL on the client in Javascript. This is easy but super bad form, and I would not recommend it since it doesn’t help your page speed and it’s unnecessarily hackish.
Use your text editor to find/replace with a reg ex to prepend the full URL to the (what I assume are ) markdown files.
Write a bash/ruby/go/node script that goes through your .md locally before publishing.
Create a global variable that contains whatever chunk of the URL you want to reuse, but this might not make it easier for you to write shorter URLs in markdown.
This is totally unsolicited, but I’d recommend having the URLs rewritten to //b.robnugen.com/images/myfancyimage.png, and drop the http when writing URLs in your markdown files. Might not apply to your current query, but it might have some benefit w/r/t other assets in a future world of SSL and mixed content errors.
The images are on the other server partially for historical reasons, but mostly because there are a lot of images and I want the image server to be their primary source (in terms of source control), not my local computer, which has a higher failure rate.
I would just put them on Github in their own repo, then clone that into my local Hugo project, but then I have to store a lot of images on my local computer (twice!) and Github (or other provider) does as well.
So my thinking was: put the images on their own server (which does thumbnailing and caching), but do not update my old journal entries which link to /images for each image.
I guess I could update all the links in all my journal entries to specify http://b.robnugen.com instead of /images + HTTP redirect, but that makes a pain in the future if I ever change my image server URI.