Use sub-domain name configuration in Laravel5

Source: Internet
Author: User

For example, local virtual primary domain name: www.learn-laravel.com, to support sub-domain names, first change the apache httpd-vhost.conf configuration, as follows:

<VirtualHost *: 80>
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
</VirtualHost>

And bind the primary domain name and sub-domain name host to the local machine.

127.0.0.1 www.learn-laravel.com
127.0.0.1 tanteng.learn-laravel.com
Here we demonstrate adding a tanteng.learn-laravel.com subdomain in Laravel5.

Next, you only need to configure the sub-domain name in one step, which is very convenient.

Add the sub-domain routing configuration in routes. php of Laravel5, for example, file location: D: \ xampp \ htdocs \ laravelCMS \ app \ Http \ routes. php

$ Router-> group (['domain '=> 'tanteng .learn-laravel.com'], function ()
{
 
Route: get ('/', function ()
    {
Echo 'Hello, world! ';
});
 
Route: get ('/test', function ()
    {
Echo 'test ';
});
 
});

Access the tanteng.learn-laravel.com directly to display "hello, world !".

Access tanteng.learn-laravel.com/testto display testtesttest ".

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.