-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add cookbook entry about url trailing slash redirect #3180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👍 |
|
||
You have to create a controller which will match any URL with a trailing | ||
slash, remove the trailing slash (keeping query parameters if any) and | ||
redirect to new URL with a 301 response status code:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the new URL
Fixed ! Thanks |
), array( | ||
'url' => '.*/$', | ||
'_method' => 'GET', | ||
))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$collection->add(
'remove_trailing_slash',
new Route(
'/{url}',
array(
'_controller' => 'AcmeDemoBundle:Redirecting:removeTrailingSlash',
),
array(
'url' => '.*/$',
'_method' => 'GET',
)
)
);
Done, thanks for your feedback. |
=================================== | ||
|
||
The goal of this tutorial is to demonstrate how to redirect URLs with | ||
trailing slash to the same URL without trailing slash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a
Just pushed some updates with a note about POST redirects (taken from @stof explanation). |
Add cookbook entry about url trailing slash redirect
Great work Emmanuel! This answers a small question very efficiently and understandably. This is a nice edition to the cookbook! Thanks! |
Thanks everyone for the feedback and for the merge ! |
Like @wouterj said in this symfony CMF discussion, it may be interesting to have this in the symfony cookbook.