astina/redirect-manager-bundle
Installation:
composer require astina/redirect-manager-bundle
Add to AppKernel.php:
new Astina\Bundle\RedirectManagerBundle\AstinaRedirectManagerBundle(),
Routing:
Import in app/config/routing.yml:
astina_redirect_manager:
resource: "@AstinaRedirectManagerBundle/Resources/config/routing.yml"
prefix: /admin/redirects # Customize prefix as needed
Database: Run schema update:
php app/console doctrine:schema:update --force
Access GUI:
Navigate to /admin/redirects (or your custom prefix) to manage redirects via the web interface.
Via GUI:
/admin/redirects/new.urlFrom (e.g., /old-page) and urlTo (e.g., /new-page).Via CLI (Bulk Import):
Create a CSV (from,to) and import:
php app/console armb:import /path/to/redirects.csv --redirect-code=301
Dynamic Redirects in Controllers:
Use the RedirectManager service to check redirects on-the-fly:
use Astina\Bundle\RedirectManagerBundle\Manager\RedirectManager;
public function someAction(RedirectManager $redirectManager)
{
$redirect = $redirectManager->findRedirect('/current-url');
if ($redirect) {
return $this->redirect($redirect->getUrlTo(), $redirect->getHttpCode());
}
// ... rest of logic
}
Subdomain Redirects:
Configure in config.yml:
astina_redirect_manager:
redirect_subdomains:
route_name: app_homepage
route_params: { locale: 'en' }
redirect_code: 301
Ensure router.request_context.host is set in parameters.yml:
router.request_context.host: yourdomain.com
Grouping Redirects:
Domain Restrictions:
Configure regex patterns in the GUI to restrict redirects to specific domains (e.g., *.example.com).
Event Listeners: Disable listeners if using a service-oriented architecture:
astina_redirect_manager:
enable_listeners: false
Manually trigger redirects in events:
$redirectManager->redirectIfNeeded($request);
Custom Layout: Override the default Twig layout:
astina_redirect_manager:
base_layout: "YourBundle:Layouts/admin.html.twig"
Doctrine Entity Manager: Use a custom manager for multi-DB setups:
astina_redirect_manager:
storage:
entity_manager: redirect_manager
Circular Redirect Prevention:
The bundle automatically detects and blocks loops (e.g., A -> B -> A).
Subdomain Redirects:
router.request_context.host is misconfigured.router.request_context.host in parameters.yml:
router.request_context.host: yourdomain.com
redirect_subdomains_ignore_hosts to exclude specific subdomains:
astina_redirect_manager:
redirect_subdomains_ignore_hosts: ['blog', 'static']
Full URL Matching:
http://example.com/old) may not work if the domain changes./old) or configure domain patterns in the GUI.CSV Import:
from,to columns (no headers or extra data).Circular Redirects:
$redirectManager->redirectIfNeeded($request) to leverage built-in checks.Redirect Not Triggering:
enable_listeners: true).urlFrom matches the incoming request (case-sensitive for exact matches).Database Issues:
php app/console doctrine:schema:update --force
php app/console cache:clear
Performance:
Redirect entity.Custom Redirect Logic:
Extend the RedirectManager service:
// services.yml
astina_redirect_manager.manager:
class: AppBundle\Service\CustomRedirectManager
parent: astina_redirect_manager.manager
calls:
- [setCustomLogic, [@some_service]]
Override Twig Templates:
Copy templates from AstinaRedirectManagerBundle/Resources/views/ to your bundle’s Resources/views/AstinaRedirectManagerBundle/ to customize the admin panel.
Add Redirect Sources:
Extend the Redirect entity or create a custom table to store additional metadata (e.g., created_by, priority).
API Access: Expose redirects via a custom API endpoint:
public function getRedirectsAction(Request $request)
{
return $this->json($this->getDoctrine()
->getRepository('AstinaRedirectManagerBundle:Redirect')
->findAll());
}
Default HTTP Code:
Override globally in config.yml:
astina_redirect_manager:
default_redirect_code: 301
Entity Manager:
redirect) has access to the Redirect entity.storage.entity_manager option.Translations:
framework.translator is enabled in config.yml.Symfony 3.4+:
How can I help you explore Laravel packages today?