📚 Encyclopedia

Web Development · updated 2026-11-23

Taking .php out of page addresses without breaking old links

phpurlsredirectsapachefallbackresourcerewriteroutingservice-worker

A site made of plain PHP files shows its file names in every address: /watch.php?v=cat, /doc.php?t=abc. Clean addresses (/watch/cat, /doc/abc) are shorter to share and no longer tie the URL to the implementation. The work is small, but the old addresses are already in texts, emails and bookmarks, so the change is mostly about keeping them alive. Done on two sites in 2026-11 (a video site and a quoting app), with two different routing methods.

Decide what is worth changing

Only addresses a person sees or shares matter: pages, sign-in, links sent to customers. Endpoints that only scripts fetch (api.php, upload handlers, form posts) gain nothing and can break things:

Leave those alone on purpose and write down that it was on purpose, so nobody "finishes the job" later.

Routing: two ways

Either way the page files stay where they are. That is what makes the redirect step easy.

Retire the old address from inside the page

Each page file starts with one helper call that knows its clean address:

One function, called first thing in every page, also means a new page cannot forget its redirect.

Things that break quietly

Testing

Write the address checks as a script that takes a base URL: every clean page answers 200, every old form answers 301 with the right Location and query, no served page still contains a .php link, unknown paths 404. Run it against the local dev server before the deploy and read-only against the live site after. When verifying a customer-facing link live, a made-up token that renders the "not available" page proves the routing without putting test data in the production database.

See also

Linked from

Sources: justinahampton memory (videos-urls-and-previews), plumb memory (plumb-clean-urls), tldr post #1913 (2026-11-20)