如何重定向到主机文件中的共享虚拟托管站点?
我想更改我的主机文件以将网址重定向到我的网站...
通常我会这样做...ping mysite.com
然后在主机文件中,如果 IP 为 99.99 .99.99,我会写...
99.99.99.99 siteiwanttoredirect.com
但在这种情况下,我的网站位于虚拟共享主机上...这意味着我从 ping 中返回的 IP 与其他一些网站相同,如果我在地址栏上,www.mysite.com 不会出现。这里有更多细节:有人提出了有关 为什么 ping 它不会给出正确的 IP。
所以我想知道的是......如果您使用虚拟共享主机,如何在主机文件中指定重定向到您的站点?
谢谢,
马特
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在共享主机上,您获得的网站由您请求的域名决定,这要归功于 主机 HTTP 标头。为了使其正常工作,需要正确配置 Web 服务器,以便它知道响应哪个主机请求而提供哪个网站 - 这通常在 CPanel 驱动的共享主机上称为“附加域”。
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.
你不能。使用主机文件,您可以更改 IP 地址,但您的共享托管提供商需要正确设置 HTTP 主机标头 - 在您的情况下,它仍然是 siteiwanttoredirect.com 而不是 mysite.com 。因此,您的托管提供商将不知道要显示谁的网站。
您可以做的是重定向到您控制的某个主机(fi localhost)并在那里运行代理服务器。如果您在计算机上设置 Apache,并使用 siteiwanttoredirect.com 的虚拟主机(它对 mysite.com 进行反向代理),那么它应该可以工作。
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.
这是通过网站的主机标头处理的,而不是本地计算机上的任何内容(例如主机文件)。
我会确保您的主机已进行此设置,然后只要人们通过网站名称而不是 IP 访问您的站点,一切都应该正常。
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.