diff --git a/cookbook/index.rst b/cookbook/index.rst index b367a491..91976698 100644 --- a/cookbook/index.rst +++ b/cookbook/index.rst @@ -9,7 +9,6 @@ The Cookbook database/choosing_storage_layer editions/cmf_sandbox editions/cmf_core - routing/remove_trailing_slash installing_configuring_doctrine_phpcr_odm creating_cms_using_cmf_and_sonata using_blockbundle_and_contentbundle diff --git a/cookbook/map.rst.inc b/cookbook/map.rst.inc index 1d3ac1e4..875f2391 100644 --- a/cookbook/map.rst.inc +++ b/cookbook/map.rst.inc @@ -7,10 +7,6 @@ * :doc:`editions/cmf_sandbox` * :doc:`editions/cmf_core` -* **Routing** - - * :doc:`routing/remove_trailing_slash` - * :doc:`create_new_project_phpcr_odm` * :doc:`create_basic_cms_auto_routing` * :doc:`installing_configuring_doctrine_phpcr_odm` diff --git a/cookbook/routing/remove_trailing_slash.rst b/cookbook/routing/remove_trailing_slash.rst deleted file mode 100644 index 3d95027a..00000000 --- a/cookbook/routing/remove_trailing_slash.rst +++ /dev/null @@ -1,82 +0,0 @@ -.. index:: - single: Redirect URLs with a trailing slash - -Redirect URLs With a Trailing Slash -=================================== - -The goal of this tutorial is to demonstrate how to redirect URLs with -trailing slash to the same url without trailing slash -(for example ``/en/blog/`` to ``/en/blog``). - -.. note:: - - For the moment, the :doc:`RoutingBundle <../../bundles/routing/introduction>` - can't achieve this automatically. - -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:: - - // src/Acme/DemoBundle/Controller/RedirectingController.php - namespace Acme\DemoBundle\Controller; - - use Symfony\Bundle\FrameworkBundle\Controller\Controller; - use Symfony\Component\HttpFoundation\Request; - - class RedirectingController extends Controller - { - public function removeTrailingSlashAction(Request $request) - { - $pathInfo = $request->getPathInfo(); - $requestUri = $request->getRequestUri(); - - $url = str_replace($pathInfo, rtrim($pathInfo, ' /'), $requestUri); - - return $this->redirect($url, 301); - } - } - -And after that, register this controller to be executed whenever a url -with a trailing slash is requested: - -.. configuration-block:: - - .. code-block:: yaml - - remove_trailing_slash: - path: /{url} - defaults: { _controller: AcmeDemoBundle:Redirecting:removeTrailingSlash } - requirements: - url: .*/$ - _method: GET - - - .. code-block:: xml - - - - - AcmeDemoBundle:Redirecting:removeTrailingSlash - .*/$ - GET - - - - .. code-block:: php - - use Symfony\Component\Routing\RouteCollection; - use Symfony\Component\Routing\Route; - - $collection = new RouteCollection(); - $collection->add('remove_trailing_slash', new Route('/{url}', array( - '_controller' => 'AcmeDemoBundle:Redirecting:removeTrailingSlash', - ), array( - 'url' => '.*/$', - '_method' => 'GET', - ))); - -.. caution:: - - Make sure to include this route *last* in your routing configuration. - Otherwise you risk to redirect Symfony2 core routes that actually - should have a trailing slash. diff --git a/index.rst b/index.rst index 65fbaa61..ed889429 100644 --- a/index.rst +++ b/index.rst @@ -140,7 +140,6 @@ Want to know more about the CMF and how each part can be configured? There's a t cookbook/database/choosing_storage_layer cookbook/editions/cmf_core cookbook/editions/cmf_sandbox - cookbook/routing/remove_trailing_slash cookbook/handling_multilang_documents cookbook/installing_configuring_doctrine_phpcr_odm cookbook/using_blockbundle_and_contentbundle