/ etc / hosts将域redirect到localhost /目录

在这个例子中,我试图强制test.com加载本地主机/项目

127.0.0.1/project test.com 

但是它不起作用。

 127.0.0.1 test.com 

以上的作品,但我真的需要它去/项目。 任何想法?

/etc/hosts不能这样工作。 这只是一个IP地址到名称的映射。 基本上在一个文本文件中的DNS。 你需要configuration你的web服务器,不pipe是什么,redirect任何请求到根目录去/项目。 一种方法可能是将文档根目录设置为直接指向/ project文件夹。

编辑/主持人:

127.0.0.1根控制台matrix

使用以下命令编辑/ etc / apache2 / sites-enabled / 000-default:

 <VirtualHost *:8080> ServerName [projectname] ServerAdmin webmaster@localhost DocumentRoot /home/count/Workspace/[projectname]/ <Directory /home/count/Workspace/[projectname]/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost> 

最后设置端口来听取所有:

 NameVirtualHost * Listen 80 Listen 8080 

然后重新启动,你可以例如,有domain.com加载本地/ [项目名称]

不知道你为什么说这是无法完成的。 :/嗯

忘记/ etc / hosts为此。 / etc / hosts是回答“这个名字属于哪个IP”的旧方法。 它与文件或[web]服务的组织方式无关。

如果你想操纵networkingstream量,使用适合的工具。 例如代理。

这需要在Web服务器级别完成。 但是,您确实需要/ etc / host条目而不使用斜线项目部分。 如果你使用Apache httpd作为你的web服务器,那么看看url重写教程。 一个简单的例子,我认为会为你工作将添加到httpd.conf或一些conf httpd.conf说包括

 RedirectPermanent /project http://test.com 

你需要在httpd中加载mod_alias模块才能工作。 很可能你已经有了。