HTTP Routing options

I have the following options in my HTTP route configuration

'options' => [
  'route' => '[:4th.]:3rd.:2nd.[:1st]',
  'constraints' => [
  '4th' => '.*?',
  '3rd' => 'mydomain',
  '2nd' => 'com',
  '1st' => '.*?',
  ],
],

but I get Missing parameter “3rd” on www.mydomain.com.local, mydomain.com.local
Any idea what I’m doing wrong here?
Thanks in advance.

Hello and welcome to our forums! :smiley:

Which route type do you use here?

Unfortunately I do not understand this part. The last part is optional, so you allow something like mydomain.com. – with dot at the end?

Hi,

The route type is Hostname.

I would like to have the following domains working.

www.mydomain.com
mydomain.com
www.mydomain.com.local
mydomain.com.local

The www and local should be optional

This means that your definition contains an error, as the last dot must also be optional.

But I do not understand the goal of this route. Do you need the individual parameters in your application? Otherwise, you could remove this route and let the server do the work.

Please let me try to explain me better.

I have two websites. ie mydomain.es and mydomain.ie each one in a separate laminas MVC module. The current route configuration looks like this:
For mydomain.ie

return [
    'router' => [
        'routes' => [
            'mydomain.ie' => [
                'type' => Http\Hostname::class,
                'options' => [
                    'route' => 'mydomain.ie',
                ],
....

For mydomain.es

return [
    'router' => [
        'routes' => [
            'mydomain.es' => [
                'type' => Http\Hostname::class,
                'options' => [
                    'route' => 'mydomain.es',
                ],
....

mydomain.ie and mydomain.es work with the above configuration but I get 404 for www.mydomain.ie and www.mydomain.es.

Otherwise, you could remove this route and let the server do the work.

Probably the best solution but now I’m intrigued, maybe I’m going to need a subdomain in the future. :slight_smile:

Thank you for your support.

In this case set the first part as optional ('[:subdomain.]mydomain.ie', '[:subdomain.]mydomain.es') and add a constraint for both on what is allowed.

Unfortunately, I can’t test it myself right now, so you would have to try out if my suggestion works.

If you need some more examples, check the related unit tests:

For now I created another route for www as following

return [
    'router' => [
        'routes' => [
            'www.mydomain.es' => [
                'type' => Http\Hostname::class,
                'options' => [
                    'route' => 'www.mydomain.es',
                ],
                'may_terminate' => true,
                'child_routes' => $child_routes,
            ],
            'mydomain.es' => [
                'type' => Http\Hostname::class,
                'options' => [
                    'route' => 'mydomain.es',
                ],
                'may_terminate' => true,
                'child_routes' => $child_routes,
            ],
        ],
    ],

I will keep playing with routes and learn a bit more as soon as I can.

Thanks again!