URL Redirection System Documentation

URL Redirection System Documentation

Overview

The URL Redirection System allows you to create intelligent redirects that can handle dynamic URL patterns, wildcards, and regex patterns. This system is particularly useful for migrating old URLs to new structures, handling dynamic content, and maintaining SEO-friendly redirects.

404 Request → ├── Check excluded paths (static files, etc.) ├── **Tier 1: Simple Redirects** │ ├── Check Redirect model for exact matches │ ├── Handle trailing slash variations │ └── Handle query parameters ├── **Tier 2: Pattern Redirects** (if Tier 1 fails) │ ├── Check RedirectApplication for pattern matches │ ├── Use wildcard/regex pattern matching │ └── Apply variable substitution ├── Language code handling └── 404 logging and custom error page

Features

  • Pattern Matching: Support for normal URLs, wildcards (*), and regex patterns

  • Dynamic Variables: Use captured groups in redirect URLs with $1, $2, etc.

  • Query Parameter Preservation: Automatically preserves query parameters during redirects


Getting Started

Accessing the Admin Interface

  1. Navigate to Django Admin

  2. Go to Pinogy RedirectPattern Redirects

  3. Click Add Pattern Redirect

    image-20251002-171944.png

Basic Configuration

Each redirect requires:

  • Source URL Pattern: The pattern to match incoming URLs

  • Available Pages: The target CMS page for the redirect

  • Extra path after the selected page: Optional additional path with variable support

  • Site: The site this redirect applies to

Pattern Types

Type

Pattern

Target Page

Extra Part

Input

Output

Type

Pattern

Target Page

Extra Part

Input

Output

Normal

/old-blog/

/new-blog/

(empty)

/old-blog/

/new-blog/

Single Wildcard

/blog/*

/articles/

$1/

/blog/my-article/

/articles/my-article/

Multiple Wildcards

/blog/*/posts/*

/content/

$1/articles/$2/

/blog/2023/posts/tech/

/content/2023/articles/tech/

Leading Wildcard

*/articles/*

/

$1/blog/$2/

/something/article/something/

/something/blog/something/

Leading Wildcard

*/articles/*

/location/

$1/blog/$2/

/something/articles/something/

/location/something/blog/something/

Regex

^/blog/([0-9]{4})/([^/]+)/$

/articles/

$2/$1/

/blog/2023/tech-news/

/articles/tech-news/2023/

Variable Substitution

Variable

Description

Pattern

Extra Part

Input

Output

Variable

Description

Pattern

Extra Part

Input

Output

$1

First capture group

^/blog/([0-9]{4})/([0-9]{2})/([^/]+)/$

$1/$2/$3/

/blog/2023/12/christmas/

/target-page/2023/12/christmas/

$2

Second capture group

*/category/*/item/*

$2/products/$3/

/old/category/electronics/item/laptop/

/target-page/electronics/products/laptop/

$3

Third capture group

^/legacy/([^/]+)/([0-9]{4})/([^/]+)/$

$1/$3/$2/

/legacy/news/2023/breaking/

/target-page/news/breaking/2023/

Advanced Examples

Use Case

Pattern

Target Page

Extra Part

Input

Output

Use Case

Pattern

Target Page

Extra Part

Input

Output

E-commerce Products

*/products/*/details/*

/shop/

$2/$3/

/old/products/laptop/details/macbook/

/shop/laptop/macbook/

Blog Categories

^/blog/([^/]+)/([0-9]{4})/([^/]+)/$

/articles/

$1/$2/$3/

/blog/tech/2023/ai-news/

/articles/tech/2023/ai-news/

Multi-language

*/en/*

/content/

$2/

/old/en/about/

/content/about/

Date Restructuring

^/legacy/([0-9]{4})/([0-9]{2})/([^/]+)/$

/content/

$3/$1/$2/

/legacy/2023/12/christmas/

/content/christmas/2023/12/

Important Discalimer
Be extremely careful with pattern matching and variable substitution! When creating redirect patterns, ensure your patterns are precise and tested thoroughly before adding. Only use variable substitution ($1, $2, etc.) if you are absolutely certain that the captured slug will be exactly the same in the target URL. In most of scenarios, slugs and identifiers change between old and new URL structures, so variable substitution should be used sparingly