I’d like to setup my localhost to redirect absolute urls from a specific subdomain to local paths using mod_rewrite as follow:
http://resources.website.com/img/mypic.gif
would redirect to
/Users/path-to-local-website/img/mypic.gif
so my local HTML could read
<img src="http://resources.website.com/img/mypic.gif" />
and yet refer to the local image.
What would be the RewriteCond/Rule for that? Thank you
So you have websites hosted somewhere in the cloud, and local replicas thereof where you do the development The HTML is the same, of course. You upload that without modifications. It contains absolute references to documents among your domains, such as images.
When surfing the local copy of this website, you want images to come from the local copies rather than from the cloud?
Sorry, I don’t think that is possible, at least not with
mod_rewrite. Your local server is feeding your browser URL’s which point back to the cloud. When your browser processes theses URL’s, it will send the request off to the real website. You cannot rewrite a request that went to some other server!You would have to filter the HTML that is going out to rewrite the URL’s so that those domains point back to the local server.
If only one domain is involved, the usual solution is not to use absolute links in the HTML, just ones relative to that web page. (For any links that don’t cross domains, you should use make them page relative.)
A solution would be to create a local test bed environment with its own DNS server sitting on your LAN which will resolve those domain names to your local server. Your browser is thereby fooled into going to your local server for those domains.
If your browser is on Linux or other Unix-like OS, you can simiply hack this with
/etc/hostsrather than a complex DNS setup:Now these three host names point back to the server. When your browser (running on the same machine) wants to fetch
foo.example.com/img/dog.jpgit will connect to the server at127.0.0.1.Configure that server with an
Aliasto forward the/img/URL’s as appropriate:But now, you are only seeing the local site. Not just the images. Everything is locally referenced.