Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Redirect Manager Bundle Laravel Package

astina/redirect-manager-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require astina/redirect-manager-bundle
    

    Add to AppKernel.php:

    new Astina\Bundle\RedirectManagerBundle\AstinaRedirectManagerBundle(),
    
  2. Routing: Import in app/config/routing.yml:

    astina_redirect_manager:
        resource: "@AstinaRedirectManagerBundle/Resources/config/routing.yml"
        prefix: /admin/redirects  # Customize prefix as needed
    
  3. Database: Run schema update:

    php app/console doctrine:schema:update --force
    
  4. Access GUI: Navigate to /admin/redirects (or your custom prefix) to manage redirects via the web interface.


First Use Case: Creating a Redirect

  1. Via GUI:

    • Go to /admin/redirects/new.
    • Enter urlFrom (e.g., /old-page) and urlTo (e.g., /new-page).
    • Set HTTP status code (default: 302) and optional comment/group.
    • Save.
  2. Via CLI (Bulk Import): Create a CSV (from,to) and import:

    php app/console armb:import /path/to/redirects.csv --redirect-code=301
    

Implementation Patterns

Core Workflows

  1. 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
    }
    
  2. 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
    
  3. Grouping Redirects:

    • Use the GUI to assign redirects to groups (e.g., "Marketing", "Legacy").
    • Filter redirects in the admin panel by group.
  4. Domain Restrictions: Configure regex patterns in the GUI to restrict redirects to specific domains (e.g., *.example.com).


Integration Tips

  1. Event Listeners: Disable listeners if using a service-oriented architecture:

    astina_redirect_manager:
        enable_listeners: false
    

    Manually trigger redirects in events:

    $redirectManager->redirectIfNeeded($request);
    
  2. Custom Layout: Override the default Twig layout:

    astina_redirect_manager:
        base_layout: "YourBundle:Layouts/admin.html.twig"
    
  3. Doctrine Entity Manager: Use a custom manager for multi-DB setups:

    astina_redirect_manager:
        storage:
            entity_manager: redirect_manager
    
  4. Circular Redirect Prevention: The bundle automatically detects and blocks loops (e.g., A -> B -> A).


Gotchas and Tips

Pitfalls

  1. Subdomain Redirects:

    • Issue: Subdomain redirects may fail if router.request_context.host is misconfigured.
    • Fix: Explicitly set router.request_context.host in parameters.yml:
      router.request_context.host: yourdomain.com
      
    • Ignore Hosts: Use redirect_subdomains_ignore_hosts to exclude specific subdomains:
      astina_redirect_manager:
          redirect_subdomains_ignore_hosts: ['blog', 'static']
      
  2. Full URL Matching:

    • Issue: Redirects with full URLs (e.g., http://example.com/old) may not work if the domain changes.
    • Fix: Use relative paths (e.g., /old) or configure domain patterns in the GUI.
  3. CSV Import:

    • Issue: Malformed CSV files (e.g., extra columns) may cause import failures.
    • Fix: Ensure CSV has only from,to columns (no headers or extra data).
  4. Circular Redirects:

    • Issue: Custom logic bypassing the bundle’s listener may create loops.
    • Fix: Always use $redirectManager->redirectIfNeeded($request) to leverage built-in checks.

Debugging

  1. Redirect Not Triggering:

    • Check if the listener is enabled (enable_listeners: true).
    • Verify the urlFrom matches the incoming request (case-sensitive for exact matches).
    • For regex matches, test patterns in the GUI’s "Test" field.
  2. Database Issues:

    • After updates, run:
      php app/console doctrine:schema:update --force
      
    • Clear cache if redirects appear broken:
      php app/console cache:clear
      
  3. Performance:

    • Issue: Large redirect tables may slow down the GUI.
    • Fix: Use pagination (configurable in the bundle) or add indexes to the Redirect entity.

Extension Points

  1. 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]]
    
  2. Override Twig Templates: Copy templates from AstinaRedirectManagerBundle/Resources/views/ to your bundle’s Resources/views/AstinaRedirectManagerBundle/ to customize the admin panel.

  3. Add Redirect Sources: Extend the Redirect entity or create a custom table to store additional metadata (e.g., created_by, priority).

  4. API Access: Expose redirects via a custom API endpoint:

    public function getRedirectsAction(Request $request)
    {
        return $this->json($this->getDoctrine()
            ->getRepository('AstinaRedirectManagerBundle:Redirect')
            ->findAll());
    }
    

Configuration Quirks

  1. Default HTTP Code: Override globally in config.yml:

    astina_redirect_manager:
        default_redirect_code: 301
    
  2. Entity Manager:

    • If using multiple managers, ensure the configured manager (redirect) has access to the Redirect entity.
    • For Symfony 3.4+, use the storage.entity_manager option.
  3. Translations:

    • The bundle provides default translations (e.g., for the GUI). Ensure framework.translator is enabled in config.yml.
  4. Symfony 3.4+:

    • The bundle supports Symfony 3.4, but some older features (e.g., Symfony 2.1) are deprecated. Test thoroughly after upgrades.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui