M
M
Maxim Spiridonov2015-03-29 10:11:30
Apache HTTP Server
Maxim Spiridonov, 2015-03-29 10:11:30

How to implement subdomains in laravel?

Hello! The question of implementing domains on laravel is tormenting. The goal is to make a separate page for each user at the address of the type: alex.site.ru.
In the route I made an entry like:

Route::group(array('domain' => '{subdomain}.lar.ru'), function()
{
    Route::get('/', '[email protected]');

  Route::get('/news', '[email protected]');
});

The site is developed locally on xampp. Apache added the following lines to the Apache config for subdomains to work from subdirectories:
<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName lar.ru
    ServerAlias *.lar.ru

    VirtualDocumentRoot C:\xampp\htdocs\lar.ru\subdomains\%1

    <Directory />
        Options FollowSymLinks
        AllowOverride all
        Require all denied
    </Directory>
    <Directory C:\xampp\htdocs\lar.ru\subdomains\*>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        DirectoryIndex index.php
        Require all granted
    </Directory>
</VirtualHost>

This option works, but not as I need. It is necessary that subdomains use the lara from the main lar.ru directory, and not so that each subdomain folder has a separate lara. It is planned to store various user files in subdomain folders.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Gavrilov, 2015-03-29
@thestump

What if we make a folder structure like this:
/laravel
/helpers
/domain
-----/www
-----/subdomain1
-----/subdomain2
-----/subdomain3
Everything in the www and subdomain folders are accessed files in the laravel and helpers folders which are in a single copy.
And we divide everything with Apache, where in VirtualHost we define the DocumentRoot parameter for each domain and subdomain , respectively
:
respectively www/laravel_project/domian/subdomain3

D
Dmitry, 2015-03-29
@thewind

And in the Apache configs, you do not need to specify the DocumentRoot and maybe everything will work out?

N
Nodlik, 2015-03-31
@Nodlik

Try mod_rewrite. That is, send a request for userName.site.ru to site.ru/users/userName, and this route is already processed by the framework.
Something like this.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.site.ru
RewriteCond %{HTTP_HOST} ([^.]+)\.site.ru
RewriteRule ^(.*)$ /users/%1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question