Last active
October 8, 2017 18:25
-
-
Save PauliusKrutkis/b2b0a5e923fa0992a9e77a0495fcaed0 to your computer and use it in GitHub Desktop.
Symfony - simple 301 redirects setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
about-us: about | |
news: blog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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