Support the ongoing development of Laravel.io →
posted 10 years ago
Requests
Last updated 1 year ago.
0

Yes, this is possible. I did something similar, until I realized that subdomains really ain't that great (for me) and a first-level route is better. Anyways, in your apache configuration you'd do something like this for every "main" subdomain:

<VirtualHost *:80>
                ServerName staging.sitename.com
                DocumentRoot /var/www/staging/public
                ServerAlias *.staging.sitename.com
                SetEnv MY_LARAVEL_ENV "staging"
                <Directory /var/www/staging/public>
                        <IfModule mod_rewrite.c>
                                Options -MultiViews
                                RewriteEngine On
                                RewriteCond %{REQUEST_FILENAME} !-f
                                RewriteRule ^ index.php [L]
                        </IfModule>
                </Directory>
</VirtualHost>

Then at the top of your route file, you can grab the environment you set with apache above. Something like this for different main domains:

if (App::environment() == 'staging')
{
	$domain = 'staging.sitename.com';
}
elseif (App::environment() == 'live')
{
	$domain = 'sitename.com';
}

Route::group(array('domain' => '{company}.'.$domain), function()
{
    /* put your routes here */
    Route::get('/', 'YourController@getCompany');
});
Last updated 1 year ago.
0

Thanks. I also have a local environment set up, with the form sitename.localhost.com. Unfortunately, I have to do php artisan serve to run the app properly and then I access it with localhost:8000. When I try to route like test.localhost:8000, it fails. Any ideas for getting around this? How did you handle local development? Thanks!

Last updated 1 year ago.
0

did you found any solutions?

0

For local development, you need a set of hostnames that point to the local host. You can set them up for just yourself, with edits to /etc/hosts on a unix/mac system, or to C:\Windows\System32\Drivers\etc\hosts on Windows. You can just make a list:

127.0.0.1 localhost thing.localhost thing2.localhost, or even use any arbitrary names (even ones you don't control, this is just changing your computer's view)

You can also do this in DNS — on any domain name you can add records like so:

thing1.local IN A 127.0.0.1
thing2.local IN A 127.0.0.1
thing3.local IN A 127.0.0.1

And then access thing1.local.example.org if you did this for the example.org domain.

It's best to use something that's at least three parts (separated by .) because the rules around cookies and subdomains are weird and counterintuitive and trying to do multiple domains under localhost without a third part makes some of those weird rules bite you.

Last updated 5 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.