views:

162

answers:

3

Hi,

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

A: 

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.

Wim
What about mapping a host name to another host name? instead of 99.99.99.99 siteiwanttoredirectto.com can I do something similar to mysite.com siteiwanttoredirectto.com?
Matt
Not with the *hosts* file, it is used at a very low level purely as an addition to DNS. Maybe there are Firefox plugins that could to this, but I don't know about those. The forwarding trick by a webserver on localhost is the only working method I can currently think of...
Wim
A: 

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.

AaronS
This is for myself, not for other people... I just wanna be able to access it with another name
Matt
You cannot do this. Unless your host has a host files entry for the domain name you are trying to hit, it won't work since the web server won't know which site to hand the request off to.
AaronS
A: 

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.

robertc
If you're allowed to host `siteiwanttoredirect.com` on your shared hosting package, this is the way to do it. If siteiwanttoredirect.com == microsoft.com however, they (hopefully!) won't let you do that.
Wim
I just want it to be like that on my computer... not on anyone elses.
Matt