# Create an URL with Hostname type and relative URL

**URL:** <https://discourse.laminas.dev/t/create-an-url-with-hostname-type-and-relative-url/2589>\
**Category:** Components & MVC\
**Tags:** zend-mvc, laminas-view\
**Created:** [November 7, 2021, 2:59pm UTC](https://discourse.laminas.dev/t/create-an-url-with-hostname-type-and-relative-url/2589 "2021-11-07T14:59:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JulienH](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@JulienH](https://discourse.laminas.dev/u/JulienH)\
**Post date:** [November 7, 2021, 2:59pm UTC](https://discourse.laminas.dev/t/create-an-url-with-hostname-type-and-relative-url/2589/1 "2021-11-07T14:59:25Z")

</div>

Hello,

I would like to create an URL with `$this->url()` in my view and using a Hostname type in my module.config.php file:

```auto
'front' => [
                'type' => Hostname::class,
                'options' => [
                    'route' => '[:subdomain]example[:domainname]',
                    'constraints' => [
                        'subdomain' => 'localv2.|',
                        'domainname' => '.com|.local',
                    ],
                ],
                'may_terminate' => true,
                'child_routes' => [
                    'home' => [
                        'type' => Segment::class,
                        'options' => [
                            'route' => '/[:locale/]',
                            'constraints' => [
                                'locale' => 'fr',
                            ],
                            'defaults' => [
                                'controller' => Controller\IndexController::class,
                                'action' => 'index',
                                'locale' => 'en'
                            ],
                        ],
                        'may_terminate' => true,
                        'child_routes' => [
                            'api' => [
                                'type' => Segment::class,
                                'options' => [
                                    'route' => '{uriapi}',
                                    'defaults' => [
                                        'controller' => Controller\IndexController::class,
                                        'action' => 'api',
                                    ],
                                ],
                                'may_terminate' => true
                            ],
                        ]
                    ],
                ],
],

```

The problem is when I create an URL for the route `front/home/api` I have the URL `https://localv2.example.com/en/api` or `https://localv2.example.com/fr/api`, the problem is that I would like the URL `/en/api` or `/fr/api`.

I also tried `$this->url('front/home/api', [], ['force_canonical' => false])` but it doesn’t works.

What I’m doing wrong please ?  
Thank you.

---

<div class="post-metadata">

**Author:** ![JulienH](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@JulienH](https://discourse.laminas.dev/u/JulienH)\
**Post date:** [November 8, 2021, 7:49am UTC](https://discourse.laminas.dev/t/create-an-url-with-hostname-type-and-relative-url/2589/2 "2021-11-08T07:49:12Z")

</div>

There is a solution to override the creation of the URL for the controller, view and the navigation in one place please ?  
I would like to fix this by removing ‘[https://localv2.example.com](https://localv2.example.com)’ and also ‘/en/’ for English pages.  
Thank you.
