I’ve set up a wildcard subdomain *.domain.com & i’m using the following .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www\.
RewriteCond %{HTTP_HOST} (.*)\.domain\.com
RewriteRule .* index.php?username=%1 [L]
Everything works perfectly.
I want to implement this method in laravel. Mainly I want to have my user’s profile displayed when you go to username.domain.com. Any ideas on achieving this?
This is easy. Firstly – do NOT change the
.htaccessfile from the default provided by Laravel. By default all requests to your domain will be routed to yourindex.phpfile which is exactly what we want.Then in your
routes.phpfile just use a ‘before’ filter, which filters all requests to your application before anything else is done.edit: if you have a country extension (i.e. domain.com.au or domain.com.eu) then you will want to change the count($server) to check for 4, not 3