T
T
TigranAM2012-01-02 19:48:45
symfony
TigranAM, 2012-01-02 19:48:45

Routing in Symfony2?

The question is this: in Symfony2, the /contact/ and /contact routes are different things. But it would be convenient for me if both options worked, or there was a redirect to the “correct” one.
I know one solution: if you put "/" at the end of the route, like this

contactform:<br>
    pattern: /contact/<br>
    defaults: { _controller: "WebsiteProjectBundle:Home:contact"}<br>

then send a redirect from /contact to /contact/ , and everything works. But there is one big minus: in this case, backslash should be in all routes, which is not convenient if many third-party packages are used, the code of which I am not going to edit. I
compiled the following .htaccess for the Apache server:
<IfModule mod_rewrite.c><br>
    RewriteEngine On<br><br>
    RewriteCond %{HTTPS} =on<br>
    RewriteRule ^(.+)/$ https://%{HTTP_HOST}/$1 [R=301,L]<br><br>
    RewriteCond %{HTTPS} =off<br>
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]	<br><br>
    RewriteCond %{REQUEST_FILENAME} !-f<br>
    RewriteRule ^(.*)$ app.php [QSA,L]<br>
</IfModule>

Is .htaccess correct? You can suggest other solutions as well.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shagguboy, 2012-01-02
@shagguboy

symfony.com/doc/2.0/cookbook/routing/slash_in_parameter.html

D
den1n, 2012-01-02
@den1n

I'm not familiar with Symfony2, but still ... If pattern is regex, then it can put "?" at the end?
Thus - /contacts/?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question