Black Friday: the Laravel testing course is $149 instead of $249, through Dec 7. See the course →
logo

How to route based on the requested domain

Useful if you serve multiple sites out of the same Laravel app

Joel Clermont
Joel Clermont
2025-11-07

From our daily Laravel tips email. Get the next one in your inbox.

The Laravel docs have great information on how to set up routing based on subdomains.

But recently someone asked if we could do the same with main domains instead of subdomains, and whether we could serve the same route with different content based on the domain.

In today's video, I show how to do this using easily with two small changes to my routes file, and a little local setup for the domain.

Watch Now (3 min)

And after watching, don't forget to subscribe to our YouTube channel, so you don't miss future videos.

Here to help,

Joel

P.S. Want a friendly, low-noise place to ask your Laravel questions? Check out the Mastering Laravel community. I hope to see you inside.

Want a tip like this in your inbox every weekday?

Each one takes less than 2 minutes to read. Join 4,000+ Laravel developers who already get them.

email
No spam. Only real-world advice.
Toss a coin in the jar if you found this helpful.