php – Dynamic subdomain laravel: when http:// or with www. redirected to homepage-ThrowExceptions

Exception or error:

For each of our customers I create a special subdomain. When the user visits e.g. https://{company-slug} it correctly shows the page.
However, when an user visits http://{company-slug} and http://www.{company-slug}, it will be redirected to our homepage.

My htaccess:

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews

RewriteEngine On

# 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]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

And the route group in routes > web.php in Laravel:

        'domain' => '{subdomain}.' . config('app.domain'),
        'middleware' => 'check.subdomain',
        'as' => 'company.',
        'before' => 'force.ssl'
    ], function () {
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *