Troubleshooting incorrect content on mobile redirect

41 views Asked by At

I own a domain called bigstore.com and have developed a Laravel website for it: www.bigstore.com. It's hosted on an Ubuntu 22.04 server utilizing Apache2, and the website is HTTPS-enabled. The server hosts both the domain (bigstore.com) and a subdomain (m.bigstore.com), intended for mobile browsers.

Here is the top-level directory for bigstore.com:

/var/www/bigstore/

Here is the top-level directory for m.bigstore.com:

/var/www/m.bigstore/

When a user enter www.bigstore.com into his or her mobile browser, I purposely route it to m.bigstore.com. That works great for me. I know it works because if I put an index.html file with this content:

<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph</p>
</body>
</html>

Under the m.bigstore.com top-level directory here:

/var/www/m.bigstore/public/index.html

And then type www.bigstore.com into my mobile browser; I see this:

My First Heading
My first paragraph

So that is PROOF that the traffic is being redirected correctly. However, when I DON'T USE the index.html file and instead use the m.bigstore.com index.php file as shown here:

/var/www/m.bigstore/public/index.php

Then, I type www.bigstore.com into my mobile browser, and I see the content from my MAIN domain (www.bigstore.com) Laravel site, NOT my SUBDOMAIN (m.bigstore.com) content! That's the problem. Specifically, I am seeing the content found in this file:

/var/www/bigstore/resources/view/welcome.blade.php (which is under the main top-level directory)

When I should instead be seeing the content found in this file:

/var/www/m.bigstore/resources/view/welcome.blade.php (which is under the subdomain top-level directory)

I think that index.php file under m.bigstore is causing the problem.

/var/www/m.bigstore/public/index.php has this content:

Here is its content:

 1   <?php
 2
 3   use Illuminate\Contracts\Http\Kernel;
 4   use Illuminate\Http\Request;
 5
 6   define('LARAVEL_START', microtime(true));
 7
 8   if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {require $maintenance;}
 9
10   require __DIR__.'/../vendor/autoload.php';
11
12   $app = require_once __DIR__.'/../bootstrap/app.php';
13
14   $kernel = $app->make(Kernel::class);
15
16   $response = $kernel->handle($request = Request::capture())->send();
17
18   $kernel->terminate($request, $response);

I suspect that the issue lies with Line 16 in the index.php file.

Specifically, $kernel->handle($request = Request::capture()) seems to be generating content from the main domain.

Interestingly, while Line 16 is supposed to return a "/", it seems to be interpreted as the top-level of www.bigstore.com rather than m.bigstore.com, which is puzzling. As I'm relatively new to this, I'm seeking clarification on what's happening in the index.php file. If anyone could shed light on this issue or propose a solution, regardless of whether it involves the index.php file, I would greatly appreciate it.

0

There are 0 answers