Skip to content

Instantly share code, notes, and snippets.

@newvertex
Created November 5, 2019 19:51
Show Gist options
  • Select an option

  • Save newvertex/a8bfa521262cfcf5932db971d50ad6e7 to your computer and use it in GitHub Desktop.

Select an option

Save newvertex/a8bfa521262cfcf5932db971d50ad6e7 to your computer and use it in GitHub Desktop.
simple config to use laravel subdomain route in shared host
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Force to use www just for main domain, not for any subdomain
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<?php
// Laravel route settings in web.php file
// if we want to use subdomain route we have to keep them all at the top of the main domain routes
Route::domain('admin.example.com')->group(function () {
Route::get('/', function () {
return "hello from admin subdomain!";
});
});
// Use Vue.js as SPA then we have to redirect any request to api but just show index file ;-)
Route::view('/{any}','index')->where('any', '^(?!api).*$');
@newvertex
Copy link
Author

  1. don't forget to add subdomain in the cpanel and remove the subdomain www record from domain zone editor before anyting else
  2. the subdomain have to point to the main laravel directory. i.e. public_html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment