I have a somewhat annoying problem in website development/deployment process; when I work locally on my server, the address of my program is localhost:8080/MYSERV/..., whereas when I deploy it, the address is www.mysite.com/...
I want all the links in my webpages to be hardcoded to the deployment version. I have read some hosts-file tutorials, but I'm still lost as to how to locally redirect requests to www.mysite.com/ to my local server for development. I would very much appreciate if someone could point me to the obvious one-liner. Thanks a lot in advance!
Internal links shouldn't be using absolute URLs, because then they need to be reconfigured when the site is deployed under a different hostname (as you've discovered), and make life difficult when reverse proxying is introduced. Links should preferably be relative to the current location (so that the site can easily be deployed under an arbitrary top level path), or if that's not feasible, relative to the root path (i.e.
/images/blah
). The only real reason to use an absolute URL is when linking between HTTP and HTTPS (and this is probably easier to do in the web server configuration).Your hosts file generally overrides DNS entries, but its uses are generally for problems other than the one you've described. Using absolute paths in your code isn't a good idea, so I suggest you start using relative paths instead.
To answer your question, the host file contains 2 entries per line, first the IP address followed by the hostname. So for example:
If you request www.mysite.com from your browser, there will be no DNS lookup and instead your browser will request www.mysite.com directly from 161.114.221.123. So in your case, the hosts file entry would look like this:
The only problem I can see with this setup is that when you attempt to request www.mysite.com from your browser, it will contact the remote server on port 80, where as from the example you've given it looks like your localhost webserver is actually listening on port 8080. You'll need to reconfigure your local webserver to listen on port 80, and also set up a corresponding vhosts file so that it responds to requests for www.mysite.com.