Skip to content

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

Merged
merged 1 commit into from
Nov 16, 2013

Conversation

EmmanuelVella
Copy link
Contributor

Q A
Doc fix? no
New docs? yes
Applies to 2.2+
Fixed tickets none

Like @wouterj said in this symfony CMF discussion, it may be interesting to have this in the symfony cookbook.

@wouterj
Copy link
Member

wouterj commented Nov 13, 2013

👍


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::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new URL

@EmmanuelVella
Copy link
Contributor Author

Fixed ! Thanks

), array(
'url' => '.*/$',
'_method' => 'GET',
)));
Copy link
Member

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',
        )
    )
);

@EmmanuelVella
Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a

@EmmanuelVella
Copy link
Contributor Author

Just pushed some updates with a note about POST redirects (taken from @stof explanation).

weaverryan added a commit that referenced this pull request Nov 16, 2013
Add cookbook entry about url trailing slash redirect
@weaverryan weaverryan merged commit 358f2e2 into symfony:2.2 Nov 16, 2013
@weaverryan
Copy link
Member

Great work Emmanuel! This answers a small question very efficiently and understandably. This is a nice edition to the cookbook!

Thanks!

@EmmanuelVella
Copy link
Contributor Author

Thanks everyone for the feedback and for the merge !

@EmmanuelVella EmmanuelVella deleted the redirect-trailing-slash branch November 16, 2013 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants