How can I disable the automatic redirect to the language prefixed url for an url defined in a routing.yml in my module?

I'm developing a custom sitemap.xml module, because the Simple Sitemap Xml module doe not have the options I need. I've got it just about working, except the url /sitemap.xml 301 automatically redirects to the url /lang/sitemap.xml - and it really shouldn't. How can I disable this redirect?

  • Do you have the Redirect module installed? – 4k4 Sep 25 '17 at 12:04
  • In language detection settings, disable the url prefix or assign it larger weight. – user21641 Sep 25 '17 at 14:12
  • The 3.x branch of simple_sitemap supports {variant}/sitemap.xml and also implements the no-redirect directive you are asking about. What functionality are you missing from it? – gbyte.co Dec 1 '18 at 2:47

Yes, has to be redirect.module, core doesn't do that. See https://www.drupal.org/node/2854462#comment-12047347, just add the '_disable_route_normalizer' flag to your route and you should be fine.


  path: '/sitemap.xml' 
    _controller: '\Drupal\module_sitemap\Controller\SitemapController::view'
    _title: 'View Site Map'
    _disable_route_normalizer: 'TRUE'
  • I've tried adding this flag both in the options section, and the root in my routing.yml: ` options: _disable_route_normalizer: 'TRUE' _disable_route_normalizer: 'TRUE'` Neither appears to work. Am I doing it wrong, or do I have to add it in a hook somewhere? – Menno van den Heuvel Sep 25 '17 at 14:10
  • " $route->setDefault('_disable_route_normalizer', TRUE);", which means it is in the defaults section, not options or root – Berdir Sep 25 '17 at 15:56
  • Thanks! That did the trick. I edited in the code that worked. – Menno van den Heuvel Sep 26 '17 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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