Answer the question
In order to leave comments, you need to log in
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]');
});
<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>
Answer the question
In order to leave comments, you need to log in
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
And in the Apache configs, you do not need to specify the DocumentRoot and maybe everything will work out?
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 questionAsk a Question
731 491 924 answers to any question