如何在localhost中创建子域。在使用Windows机器时,我尝试编辑windows host
文件
127.0.0.1 localhost
127.0.0.1/subdomain subdomain.localhost
获得这样的东西。
http://subdomain.localhost
的更新
首先,在没有任何背景的情况下提出这个问题,这个更新是为了提高质量。
通过编辑vhosts文件可以实现以下目的。
虚拟主机:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.com
DocumentRoot "C:/wamp/www/subdomain/"
ServerName localhost
ServerAlias subdomain.localhost
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
</VirtualHost>
现在在编辑主机时,可以解决以下问题。
主机
127.0.0.0 subdomain.localhost
现在我找到了一个更好的例子,使用RewriteRule
(适用于任何子域,而不仅仅是localhost)
在.htaccess文件中:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.example.com
RewriteRule ^(.*)$ http://example.com/subdomains/sub/$1 [L,NC,QSA]
对于更一般的规则,我们可以替换最后两行:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/subdomains/%1/$1 [L,NC,QSA]
我不是mod_rewrite专家,请帮助改进和指导。
三江源。