Jump to content

ICT:Rewrite Philosophy

From Costa Sano MediaWiki

Rewrite Philosophy for MediaWiki

MediaWiki is not a traditional website built from static files. It is a title‑driven application where almost every URL — even those that look like files — must be routed through index.php. This page explains the philosophy behind the Apache rewrite rules used on this server, so future administrators understand why the rules exist and what they protect.

1. MediaWiki routes titles, not files

A URL such as:

/Bestand:2017-1712.jpg

is not a real file. It is a page title that happens to contain a colon and end with .jpg.

If Apache treats this as a static file, MediaWiki never receives the request. This breaks:

  • file description pages
  • thumbnail generation
  • metadata extraction
  • upload history
  • namespace routing

Therefore: namespace titles must always be routed to MediaWiki.

2. Static files must be served directly — but only real ones

MediaWiki has real static assets:

  • /resources/
  • /skins/
  • /images/
  • /favicon.ico

These should bypass PHP for performance.

However, only actual files should bypass PHP — not titles that merely look like files.

This is why the rewrite rules include a safeguard to prevent namespace titles from being mistaken for static files.

3. Namespaces always contain a colon

This is the key principle.

Every namespace title follows the pattern:

/Namespace:Page

Examples:

  • Bestand:
  • File:
  • Media:
  • Research:
  • ICT:
  • any future namespace
  • any language alias

Because of this, the rewrite rules include:

RewriteCond %{REQUEST_URI} !^/[^/]+:

This ensures that any URL containing a namespace prefix is routed to MediaWiki, even if it ends with .jpg, .png, .css, or .js.

This rule is future‑proof and protects all namespaces automatically.

4. Everything else is rewritten to MediaWiki

After excluding:

  • API entry points
  • static assets
  • real files
  • MediaWiki’s own image storage

…all remaining URLs are rewritten to:

/index.php?title=$1

This ensures MediaWiki handles:

  • pages
  • categories
  • files
  • templates
  • modules
  • custom namespaces
  • extensions

This is the core of MediaWiki’s routing model.

5. Why this philosophy matters

Rewrite rules are powerful but fragile. A single misplaced rule can silently break:

  • file pages
  • thumbnails
  • namespaces
  • extensions
  • VisualEditor
  • REST endpoints

Documenting the intent behind the rules ensures that:

  • future administrators understand the logic
  • upgrades do not break routing
  • debugging is easier
  • the configuration remains stable over time

This philosophy is part of the long‑term stewardship of the system.

Summary

Rewrite only real static files. Route everything else — especially anything with a namespace — through MediaWiki.