I have created a routing URL like

  path: '/u/{company_name}/login'
    _controller: '\Drupal\login\Controller\LoginController::login_form'
    _title: 'Login'
    _permission: 'access content

This works with http://example.com/u/testcompany/login

But I want the URL like http://example.com/testcompany/login for that I write the below routing

  path: '/{company_name}/login'
    _controller: '\Drupal\login\Controller\LoginController::login_form'
    _title: 'Login'
    _permission: 'access content'

but it's not working.

Please let me know if any other way to achieve this.


should call to


may be through htaccess or any other way?

  • did you rebuild the cache?
    – Yuseferi
    Commented Oct 4, 2016 at 8:37
  • 1
    yes,actually I think drupal 8 not support to URL routing with the first parameter as a dynamic parameter. if I used with just one character (u) all is working fine as I have added first routing Commented Oct 4, 2016 at 8:55

1 Answer 1


If there is a node for each company, you can insert an alias when the node is saved. Set up the alias created for each company to start with '/company/{company_name}', then when the alias is inserted, you can add a secondary alias for login:

 * Implements hook__path_insert().
function mymodule_path_insert($path) {
  if (preg_match('/company\/(.*)/', '/company/xyz', $matches) && preg_match('/node\/(\d+)$/', $path['source'])) {
  $company_name = $matches[1];
    \Drupal::service('path.alias_storage')->save("/u/$company_name/login", "$company_name/login" $path['langcode']);

This way, the visible path will be /{company_name}/login, but the machine name as far as Drupal is concerned with be /u/{company_name}/login.

You could instead do this on entity_insert and entity_update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.