Support the ongoing development of →
Last updated 1 month ago.

jrhenderson1988 said: Is there a way I can match any domain that is not my domain or a subdomain of my domain in this way?

Yes, don't use a domain filter on the last group. Since if it makes it that far it didn't match the other routes.

I need to be able to access the domain to do something with it afterwards too, just like I did with $subdomain.

You can get the requested url domain with,

Last updated 1 month ago.

Thanks for your reply. That's what I'm doing at the moment. I was just hoping there was a way of doing it with a domain filter as it felt cleaner that way.

Thanks for the tip on Request::getHost(). I am currently using:

Last updated 1 month ago.

I know this is really late, but there is a way to do it with a domain filter. By default Laravel applies a regexp to the filter that prevents you from passing any non-alphanumeric characters. You can override this in app/Providers/RouteServiceProvider.php in the boot method with something like:

public function boot(Router $router)
    $router->pattern('domain', '[a-z0-9.]+');

Now you can do dynamic full domain routing just like you would subdomains.


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 - All rights reserved.