GitHub Stories

Agent Instructions: URL Migration for ImageMagick Website

Purpose

This agent file provides instructions for migrating pages from the /script/ directory to their own dedicated directories with cleaner URLs.

Migration Pattern (Based on defines.php Migration)

Overview

The migration follows these steps:

  1. Create a new directory with the desired URL name
  2. Move page content to the new directory’s index.php
  3. Convert old file to a 301 redirect
  4. Update all references throughout the website

Step-by-Step Process

Step 1: Create New Directory Structure

For a page currently at script/PAGENAME.php, create:

PAGENAME/
  └── index.php

The new index.php should contain:

<?php
  $title='Page Title';
  $description='Page description for SEO';
  $folder='PAGENAME';
  include('../script/session.php');
?>

Step 2: Convert Old File to Redirect

Replace the content of script/PAGENAME.php with:

<?php
  header("Location: /PAGENAME/", true, 301);
  exit();
?>

Step 3: Update All References

Search for and replace all references to the old URL pattern:

Old patterns to find:

Replace with:

Patterns to Search For

Look for these patterns in the codebase:

Example: defines.php Migration

Files Changed:

  1. Created: defines/index.php (new location)
  2. Modified: script/defines.php (now redirects)
  3. Updated references in:
    • include/command-line-options.php
    • include/formats.php

Changes Made:

Agent Execution Instructions

When asked to migrate a URL, follow these steps:

  1. Identify the page: Ask which script file to migrate (e.g., script/PAGENAME.php)

  2. Extract metadata: Read the current script file to get:
    • $title variable
    • $description variable
    • Any other specific variables
  3. Search for references: Use the search tool to find all files referencing the old URL pattern script/PAGENAME.php

  4. Create new structure:
    • Create new directory PAGENAME/
    • Create PAGENAME/index.php with proper metadata and folder variable
    • Ensure $folder variable matches directory name
  5. Convert old file: Replace content with 301 redirect

  6. Update all references:
    • Replace all old URL patterns with /PAGENAME/
    • Always use multi_replace_string_in_file when updating more than one file — batch all replacements into a single call rather than calling replace_string_in_file repeatedly
  7. Verify: Check if there are any remaining references to old URL

  8. Add new file to git: Run git add PAGENAME/index.php to stage the new file

URL Pattern Standards

Old Pattern (Deprecated)

<a href="<?php echo $_SESSION['RelativePath']?>/../script/PAGENAME.php">

New Pattern (Preferred)

<a href="/PAGENAME/">

Common Files to Check for References

Based on the defines migration, commonly updated files include:

Validation Checklist

After migration, verify:

Notes