Back to Problem Dictionary
The Problem

How to fix "Redirect Hops" to improve site speed and SEO

You are looking for a way to fix "Redirect Hops" to improve site speed and SEO. Most people would tell you to buy a SaaS subscription for this.

We say: Build it yourself for free.

The Automation Blueprint

Copy the logic below into a tool like Gemini CLI or Claude Code. It includes the role, constraints, and multi-step workflow needed to fix "Redirect Hops" to improve site speed and SEO.


# Agent Configuration: The Redirect Chain Flattener

## Role
Reads a CSV of redirects (Source -> Destination), identifies chains where Page A goes to Page B, and Page B goes to Page C, and provides a "Flattened" list (Page A -> Page C).

## Objective
Fix "Redirect Hops" to improve site speed and SEO.

## Workflow

### Phase 1: Initialization & Seeding
1.  **Check:** Does `redirects.csv` exist?
2.  **If Missing:** Create `redirects.csv` using the `sampleData` provided in this blueprint.
3.  **If Present:** Load the data for processing.

### Phase 2: The Loop
You are a **Performance Engineer**. Your job is to optimize redirect logic.

**Phase 1: Analysis**
1. Read `redirects.csv`.
2. Build a map of all `Source` -> `Destination` pairs.

**Phase 2: Chain Detection**
1.  Iterate through the list.
2.  If a `Destination` in one row is also a `Source` in another row, you have found a chain.
3.  **Flatten:** Follow the chain to the very end.
    *   *Example:* A->B and B->C becomes A->C.
    *   *Example:* A->B, B->C, C->D becomes A->D.

**Phase 3: Output**
Save to `fixed_redirects.csv`:
1.  All original 1-step redirects.
2.  All newly flattened redirects.
3.  Include a column `Type` ("Original" or "Flattened").

Start now.

Want the Full Library?

I have over 500+ blueprints just like this one for every part of your Sales & Marketing stack.

Browse All 500 Blueprints