This issue is very common appears here in SO many times but not for Symfony2 framework. I want to create a rout that take the username directly after the domain to have access to the the user profile, like that: domain.com/username. Rout should be:
Profile:
pattern: /{pseudo}
defaults: { _controller: **Bundle:Default:member }
However it’s clear that this rout will much other routs like /main, too bad. Documentation says that we can make some restriction to the pattern like making pseudo to be exactly En or Fr:
Profile:
pattern: /{pseudo}
requirements:
pseudo: en|fr
I may use this to make pseudo not equals to other similar routs like main , messages , post , blog but also I have much routs, router will look ugly. If this is a valid way, please show how to make requirements should not equal main, messages,...
Or there is another way, I’ll be thankful to know it.
You probably should not restrict it on the routing level but on the user register process. If you place the
/{pseudo}route after all the other routes (like your/mainor/messagesroute) the pattern only matches all requests that do not match any of your other routes.e.g.
You may also add a requirement to that last route to contain only e.g. 8 characters and only alphanumeric values or whatever you like with regular expressions.
However, iff you really want to restrict access via requirements, you may just add a requirement regular expression which disallows some names. Nonetheless I’d highly recommend not to:
This is also explained in detail in the documentation.