php 如何在我的本地主机上创建子域?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18793883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:13:34  来源:igfitidea点击:

How to make subdomain on my localhost?

phplocalhost

提问by Mehman Manafov

is it possible to create subdomains on my localhost? like sub.localhostand would like to know how subdomains work.

是否可以在我的本地主机上创建子域?喜欢sub.localhost并想知道子域是如何工作的。

回答by SeanWM

Create a virtual host as such:

创建一个虚拟主机,如下所示:

<VirtualHost *:80>
    ServerName sub.localhost
    DocumentRoot "C:/public_html/sub"
</VirtualHost>

And in your hosts file add this line:

并在您的主机文件中添加以下行:

127.0.0.0       sub.localhost

Hereis a useful tutorial you might find helpful.

是一个有用的教程,您可能会觉得有用。

回答by SAnDAnGE

You can make your browser to point to any domain/subdomain that you want as long as you put the ip - hostname definition in your c:\Windows\System32\drivers\etc\hostsfile, for example:

只要将 ip - 主机名定义放在c:\Windows\System32\drivers\etc\hosts文件中,您就可以让浏览器指向您想要的任何域/子域,例如:

127.0.0.1 localhost

127.0.0.1 sub.localhost

127.0.0.1 本地主机

127.0.0.1 子本地主机

or on the same line separate by space:

或在以空格分隔的同一行上:

127.0.0.1 sub.localhost subsub.localhost local.host

127.0.0.1 sub.localhost subsub.localhost local.host

回答by Athens Holloway

Add the following to your local hosts file. On windows, it's located at C:\WINDOWS\system32\drivers\etc\hosts.

将以下内容添加到本地主机文件中。在 Windows 上,它位于C:\WINDOWS\system32\drivers\etc\hosts

127.0.0.1       sub.localhost

Replace 127.0.0.1with whatever IP address you want.

替换127.0.0.1为您想要的任何 IP 地址。