Skip to content

Instantly share code, notes, and snippets.

@PauliusKrutkis
Last active October 8, 2017 18:25
Show Gist options
  • Save PauliusKrutkis/b2b0a5e923fa0992a9e77a0495fcaed0 to your computer and use it in GitHub Desktop.
Save PauliusKrutkis/b2b0a5e923fa0992a9e77a0495fcaed0 to your computer and use it in GitHub Desktop.
Symfony - simple 301 redirects setup
<?php
public function catchallAction($req)
{
$redirects = Yaml::parse(file_get_contents(__DIR__ . '/../Resources/config/redirects.yml'));
if (isset($redirects[$req])) {
return new RedirectResponse('/' . $redirects[$req], 301);
}
throw $this->createNotFoundException();
}
about-us: about
news: blog
catchall:
path: /{req}
defaults: { _controller: 'AppBundle:Default:catchall' }
requirements:
req: ".+"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment