如本地虚拟主域名:www.learn-laravel.com,如需支持子域名,首先更改apache的httpd-vhost.conf配置,如下:
DocumentRoot "/xampp/htdocs/laravelCMS/public/"
ServerName www.learn-laravel.com
ServerAlias *.learn-laravel.com
ErrorLog "logs/www.learn-laravel.com-error.log"
CustomLog "logs/www.learn-laravel.com-access.log" combined
并绑定主域名和子域名host到本机。
127.0.0.1 www.learn-laravel.com
127.0.0.1 tanteng.learn-laravel.com
这里演示在Laravel5中增加一个tanteng.learn-laravel.com的子域名。
接下来只需要一步即可完成子域名的配置,非常方便。
在Laravel5的routes.php中增加子域名路由配置,如文件位置:D:xampphtdocslaravelCMSappHttproutes.php
$router->group(['domain' => 'tanteng.learn-laravel.com'], function()
{
Route::get('/', function()
{
echo 'hello,world!';
});
Route::get('/test', function()
{
echo 'test';
});
});
直接访问tanteng.learn-laravel.com,即可显示“hello,world!”.
访问tanteng.learn-laravel.com/test,即可显示“test”.