Question

I want to change my hosts file to redirect a web address to my site...

normally I would just do... ping mysite.com then in the hosts file, if the IP came out as 99.99.99.99, I'd write...

99.99.99.99     siteiwanttoredirect.com

But in this case my site is on virtual shared hosting... which means the IP I get back from the ping is the same as a few other sites and if I type that IP in the address bar, www.mysite.com won't come up. Here's a bit more details: someone who asked a question about why pinging it wouldn't give the correct IP.

So what I would like to know is... if you're on virtual shared hosting, how can you specify redirects to your site in the hosts file?

Thanks,
Matt

Was it helpful?

Solution

You cannot. With the hosts file you can change the IP address, but your shared hosting provider needs the HTTP Host header to be set up correctly -- which in your case will still be siteiwanttoredirect.com and not mysite.com . Your hosting provider will therefor not know who's site to show.

What you could do is redirect to some host you control (f.i. localhost) and run a proxy server there. If you set up Apache on your machine, with a virtual host for siteiwanttoredirect.com which does a reverse proxy to mysite.com , it should work.

OTHER TIPS

This is handled via the host header of the website, and not anything on your local machine, like your hosts file.

I would make sure your host has that set up, then as long as people visit your sit via the website name, and not IP, everything should work.

On a shared host, the website you get is determined by the domain name you ask for thanks to the Host HTTP header. For this to work properly the web server needs to be configured correctly so it knows what website to serve in response to which Host request - this is usually called 'Add-on Domains' on CPanel driven shared hosting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top