Support the ongoing development of Laravel.io →
Configuration Laravel Middleware

Hey everyone,

I’m working on a multi-tenant eCommerce platform (nabisalay.com) where users can create their own stores.

How It Works By Default

  • Users get a store handle like: nabisalay.com/@storehandle

  • I want to let them connect their own custom domains (e.g., mystore.com).

What I’ve Implemented So Far

Middleware for Domain Mapping

I’ve added a middleware that checks the requested domain and maps it to the associated store:

public function handle(Request $request, Closure $next): Response
{
    $domain = $request->getHost(); // Get the current domain

    // Check if the domain exists in user settings
    $userSetting = UserSetting::where('custom_domain', $domain)->first();

    if ($userSetting) {
        // Get the associated username
        $username = $userSetting->user->username;
        
        // Merge the username into the request
        $request->merge(['username' => $username]);
    }

    return $next($request);
}

DNS Records I’ve Set Up

I added the following DNS records:

CNAME	www	0	nabisalay.com	300
A	@	0	89.117.27.88	300
CAA	@	0	0 issuewild "letsencrypt.org"	14400
CAA	@	0	0 issue "letsencrypt.org"	14400
CAA	@	0	0 issuewild "pki.goog"	14400
CAA	@	0	0 issue "pki.goog"	14400
CAA	@	0	0 issuewild "digicert.com"	14400
CAA	@	0	0 issue "digicert.com"	14400
CAA	@	0	0 issuewild "sectigo.com"	14400
CAA	@	0	0 issue "sectigo.com"	14400
CAA	@	0	0 issuewild "globalsign.com"	14400
CAA	@	0	0 issue "globalsign.com"	14400
CAA	@	0	0 issuewild "comodoca.com"	14400
CAA	@	0	0 issue "comodoca.com"	14400

.htaccess Configuration (Apache, Shared Hosting)

I’m on shared hosting using Apache, and this is my .htaccess file:

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

    RewriteEngine On

    # Redirect www to non-www
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

    # Redirect HTTP to HTTPS
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

The Issue

  • I successfully connected a custom domain (nabisalay.shop) to Shopify, but it doesn’t work with nabisalay.com.
  • When visiting nabisalay.shop it show this error nabisalay.shop sent an invalid response.

Questions I Need Help With

  • What might be causing the domain to work with Shopify but not with my platform?

Would love any insights or recommendations! 🚀

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Nabisalay nabisalay Joined 22 Mar 2025

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.

© 2025 Laravel.io - All rights reserved.