0

I have the following routes

hekdb_login_show:
    path: /Login/showForm
    defaults: { _controller: HEKdbBundle:Login:showForm }

hekdb:
  path: /
  defaults:
    _controller: FrameworkBundle:Redirect:redirect
    route: hekdb_login_show
    permanent: true

(Actually there are more, but these two are sufficient.) The last route is supposed to redirect everyone that comes to the website with nothing more than "/" after the hostname is redirected to the login form.

The problem is that the path "/" in the last routing rule matches every path, because every path starts with a "/". The result is an infinite redirection loop.

I read that path is interpreted as a regular expression, so I tried the pattern "^/$". But this resulted into a PHP error. Then I tried escaping the special regexp symbols "^" and "$", i.e. "\^/\$". But this did not work either.

user2690527
  • 1,729
  • 1
  • 22
  • 38

1 Answers1

1

Include this route last to pick up everything that has fallen through any existing routes. I think that is what you actually want.

zayso_core_unknown:
    pattern:  /{url}
    defaults: { _controller: ZaysoAreaBundle:Public:index, url: "unknown" }
    requirements:
       url: ".+"

Don't remember where I got it from but it does the job.

And you are mistaken about / matching everything. I often have this as my very first route:

zayso_core_index:
    pattern:  /
    defaults: { _controller: ZaysoAreaBundle:Public:index }

It works as expected.

You might want to mess a bit with app/console router:match to see what happens.

Cerad
  • 48,157
  • 8
  • 90
  • 92
  • Problem solved. But I do not know why and how. After several iterations of `php app/console cache:clear`, browser cache clearing and restarting the web server, it suddenly works as expected. >:( But you were mistaken. My only intention was to redirect the homepage "/" to a specific page that already exists anyway. If an URL does not exist the standard error behaviour is just fine. But anyway thanks. – user2690527 Aug 19 '13 at 20:55