0

I want to run some local tests on a site I have. The site is accessible at www.mysite.com. I want one particular file to be fetched from my local machine. I thought I could maybe achieve this by

  • installing Apache locally
  • adding 'localhost www.mysite.com' to my hosts file
  • configure Apache to forward all requests to www.mysite.com except for requests for the particular file www.mysite.com/myapp/myfile.css, which should be served from the Apache web server running locally.

Firstly I am not sure whether that set-up would work - in the case where a file is requested that is not my special case, the request would be forwarded to www.mysite.com/... , but would that then (because of the entry in my hosts file) go back to my local Apache server and into some infinite loop?

Secondly (and only relevant if the above is not true), how would I configure Apache to do that? I guess I need a ProxyPass but I'm having trouble figuring out exactly what.

Thanks for any help.

Paul

user265330
  • 2,533
  • 6
  • 31
  • 42

1 Answers1

0

I don't think you'll be able to do this the way you're suggesting as you'll never be able to perform a lookup to proxy to www.mysite.com if you've defined it as localhost.

You could create another domain in your hosts file, say local.mysite.com and host the desired website files there and proxy everything else to www.mysite.com:

<VirtualHost *:80>

 ServerName local.mysite.com
 DocumentRoot ...

 <Directory ...>
   ...
 </Directory>

 RewriteEngine On
 RewriteCond %{REQUEST_URI} !^/myapp/myfile.css
 RewriteRule ^(.*)$ http://www.mysite.com/$1 [P]

</VirtualHost>

Or if www.mysite.com works directly using the IP (i.e. not via virtual hosting) you could point localhost to mysite.com and use the real IP in the rewrite proxy.

<VirtualHost *:80>

 ServerName www.mysite.com
 DocumentRoot ...

 <Directory ...>
   ...
 </Directory>

 RewriteEngine On
 RewriteCond %{REQUEST_URI} !^/myapp/myfile.css
 RewriteRule ^(.*)$ http://1.2.3.4/$1 [P]

</VirtualHost>
arco444
  • 22,002
  • 12
  • 63
  • 67