This bundle adds a database table that stores redirects for your site. 404 exceptions are intercepted and the requested uri is looked up. If a match is found it redirects to the found redirects destination. The count and last accessed date can be optionally stored as well.
In addition, 404 errors can be optionally logged as well. Their count and last accessed date will also be stored. This can be useful for determining a bad link.
vendor/bundles/Zenstruck/Bundle/RedirectBundle)Zenstruck namespace to your app/autoloader.phpnew Zenstruck/Bundle/RedirectBundle/ZenstruckRedirectBundle())ZenstruckRedirectBundle to your doctrine mappings (not necessary if auto_mapping is true)Create your redirect class inheriting the MappedSuperClass this bundle provides:
namespace Acme\DemoBundle\Entity;
use Zenstruck\Bundle\RedirectBundle\Entity\Redirect as BaseRedirect;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="redirect")
*/
class Redirect extends BaseRedirect
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
Set this class in your config.yml:
zenstruck_redirect:
redirect_class: Acme\DemoBundle\Entity\Redirect
Update your schema (doctrine:schema:update --force)
You can have hash tags in your source urls. This allows mutiple source paths with different hash tags in the database. Example:
Since the server cannot tell what the hashtag is, a template with some javascript is rendered. The javascript then determines where to redirect. Try to always have a non-hashed source available as a fallback.
By default the bundle simply intercepts your application's 404 errors and trys to find a matching entry in the database.
Default configuration:
# app/config/config.yml
...
zenstruck_redirect:
redirect_class: ~ # Required
redirect_template: ZenstruckRedirectBundle:Redirect:redirect.html.twig
log_statistics: false
log_404_errors: false
...
log_statistics: when enabled, the count and last accessed date for redirects are stored in the database.log_404_errors: when enabled, 404 errors are added to the database as redirects without destinations. Their count and last accessed date are also stored.© Copyright 2011 Kevin Bond. Powered by Symfony2 and Github. Hosted with ServerGrove