Support the ongoing development of Laravel.io →
Requests
Last updated 2 years ago.
0

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,

Request::getHost() 
Last updated 2 years ago.
0

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:

Request::server('HTTP_HOST');
Last updated 2 years ago.
0

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.]+');
    parent::boot($router);
}

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2024 Laravel.io - All rights reserved.