Using a subdomain in your route
Many modern web applications offer customized content to their users, including giving them a custom subdomain where they can access their content. For example, instead of a user's profile page being http://example.com/users/37
, we might want to offer http://username.example.com
. By changing some DNS and Apache settings, we can easily provide the same functionality in Laravel.
Getting ready
For this recipe, we need access to our DNS settings and our server's Apache configurations. We'll also need a properly configured MySQL database and a standard Laravel installation. Throughout the recipe, we'll be using example.com
as the domain name.
How to do it...
To complete this recipe, follow these steps:
In the DNS for our domain name, we need to add an "A" record using a wildcard for the subdomain, such as
*.example.com
, and then point it to our server's IP address.Open up Apache's
httpd.conf
file and add a virtual host to it as follows:<VirtualHost *:80> ServerName...