Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thebigk's avatar
Level 13

Why is this route not hit?

Here's a snippet from my routes file:

Route::domain('{domain}.xyz.test')->group(function() {
    dd(url()->current());
   Route::get('/apple-orange', function() {
      return "Apple and Orange";
   });
});

Browser URL: https://abc.xyz.test/apple-orange

On my local valet installation, the output is https://abc.xyz.test/apple-orange, and commenting out the dd part gives me "Apple and Orange" as expected.

I modify the code as follows for my live-server:

Route::domain('{domain}.customer.app')->group(function() {
    dd(url()->current());
   Route::get('/apple-orange', function() {
      return "Apple and Orange";
   });
});

URL: https://support.customer.app/apple-orange

There are two scenarios:

  1. The code outputs : https://support.customer.app/apple-orange; which means the route is properly recognized by Laravel.
  2. However, when I remove the dd part, the route /apple-orange is never called; and laravel throws 404 error.

This is very strange and I am unable to figure out what's going on.

Looking for answers from a human. This LarryAI bot is utterly useless. :-(

0 likes
14 replies
jlrdw's avatar

Have you tried clearing route cache.

Also check network tab.

thebigk's avatar
Level 13

@jlrdw Yep, that's the first thing I did. No use though. What specifically should I look for in the network tab?

Actual values from my test domain:

Request URL:
https://support.waitlist.guru/apple-orange
Request Method:
GET
Status Code:
404 Not Found
Remote Address:
13.232.81.13:443
Referrer Policy:
strict-origin-when-cross-origin
Cache-Control:
no-cache, private
Content-Encoding:
gzip
Content-Length:
2140
Content-Type:
text/html; charset=UTF-8
Date:
Thu, 09 Nov 2023 05:38:59 GMT
Server:
Caddy
Status:
404 Not Found
Vary:
Accept-Encoding
X-Original-Host:
support.waitlist.guru
jlrdw's avatar

@thebigk what is the response in the network tab.

And if you try:

Route::get('apple-orange', function() {
      echo "Apple and Orange";
   });

Does it work?

Try deleting bootstrap\packages.php and bootstrap\services.php

however Do Not Delete .gitignore.

This cache folder will be automatically rebuilt.

thebigk's avatar
Level 13

@jlrdw - I put

Route::get('apple-orange', function() {
      echo "Apple and Orange";
   });

in my routes/web.php at the top. Yet, the application throws 404.

The response in the network tab is the HTML code generated by Laravel for 404 page. This indicates that Laravel is actually receiving the request; but is unable to match it to any route, even the /, /test and apple-orange.

Second, I removed /bootstrap/cache/packages.php and bootstrap/cache/services.php files. Tried agin; the application throws 404.

jlrdw's avatar

@thebigk

In your case use the slash you had, sorry:

Route::get('/apple-orange', function() {
      echo "Apple and Orange";
   });

My .htacces is setup so I can skip the first slash.

thebigk's avatar
Level 13

@jlrdw I am using caddy instead of nginx. The / does not seem to make any difference. Still a 404.

My best guess at this point is that Laravel is actually using some other route to do the match; and not the domain. I checked with Route::current() and it does show correct apple-orange.

jlrdw's avatar

@thebigk check your route list for a possible conflict you may have forgot.

thebigk's avatar
Level 13

@jlrdw Really appreciate your help, but it looks pretty clean to me:

  GET|HEAD   / ..............................................Subdomain\PostsController@index
  POST       _ignition/execute-solution .............................................. ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController
  GET|HEAD   _ignition/health-check .............................................. ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController
  POST       _ignition/update-config .............................................. ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController
  GET|HEAD   api/user ..............................................
  GET|HEAD   apple-orange ...............................................
  GET|HEAD   support.waitlist.guru/apple-orange

Is there anything to look for in the configuration section? My brain is spinning.

thebigk's avatar
Level 13

@jlrdw - It's another test URL which I tried putting like this:

Route::domain('support.waitlist.guru')->group(function() {
//    dd(Route::current());
//   dd(request()->path());
    Route::get('apple-orange', function() {
      return "Apple and Orange";
   });
});

The https://support.waitlist.guru/apple-orange url is the actual URL I put in the browser.

thebigk's avatar
Level 13

@jlrdw - I have made some progress. I edited my .env configuration setting's

APP_URL="https://support.waitlist.guru"

... and it looks like Laravel is recognizing the routes. I'm now in a fix.

How do I set the 'APP_URL` dynamically for the customer domains? Would really appreciate your support. I think I'm very close to fixing this issue.

thebigk's avatar
Level 13

@jlrdw and @snapey - It turns out that you need a proper APP_URL (i.e. config('app.url')) to make this work. I have been able to fix this by overriding the app.url in the ServieceProvider.

I am however worried if it's the safe way to do so. Not sure what I might run into. Do you have any suggestions?

Please or to participate in this conversation.