I have a very simple bundle controller
<?php
namespace Mnab\ContactBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction($anything)
{
return new \Symfony\Component\HttpFoundation\Response(__CLASS__ .' '.$anything);
//return $this->render('MnabContactBundle:Default:index.html.twig', array('name' => $anything));
}
}
I have roter config in YML files
CASE 1: My routing for this controller looks like:
mnab_contact_homepage:
pattern: contact/{anything}
defaults: { _controller: MnabContactBundle:Default:index, anything: null }
requirements:
anything: .*
In this case application accepts for this controller the following urls:
/contact /contact/ /contact/bla /contact/bla/bla/blabla
and so on
CASE 2 My routing for this controller looks like:
mnab_contact_homepage:
pattern: contact/
defaults: { _controller: MnabContactBundle:Default:index, anything: null }
requirements:
anything: .*
In this case application accepts only
/contact/
and
if there is url:
/contact -> it makes redirection (dont' know what type 301 or 302) to /contact/ url
CASE 3 My routing for this controller looks like:
mnab_contact_homepage:
pattern: contact
defaults: { _controller: MnabContactBundle:Default:index, anything: null }
requirements:
anything: .*
In this case application accepts only
/contact
Expected results
In case 3 everything is as I expect but case 1 and 2 works not as I expect
Questions
Why in case 1 application accepts also /contact url ? I have clearly expect /contact/ url not contact/
Why in case 2 applications accepts also /contact url making redirection for it to /contact/
Why behaviour is different in case 1 and case 2
Is it possible to change this behaviour - for example not accept at all /contact in my case ? (In fact I don't mind because I want some urls with trailing slash but in case 1 I'll have to do redirection for version without trailing slash)
Does Symfony do such "tricks" for all urls (also with extension as for example I define it works for /test.html and Symfony makes it work also for /test.html/ ) or only for those without extension?
Where can I read a bit more about such cases?