Redirect an old address

v0.0.3

When a page or a file moves, the old address still gets visits from search engines, shared links and bookmarks. A redirect rule answers a request for the old address. It can send the visitor to the new one, serve another page of the site at the old address, or answer with the site's 410 or 404 page. This guide adds a rule, explains what it matches and which rules the CMS refuses, and shows how to check that it works.

Before you begin

  • Every dashboard admin can read the list of rules. Adding, editing and archiving take admin:dashboard:runtime:redirect, or a wildcard that covers it, such as admin:dashboard:runtime:*. Without it, the buttons that write are not drawn. See How permissions work.
  • A rule belongs to one site and answers requests for that site's domain only. A master picks the site when it adds a rule. A site account adds rules to its own site.
  • Know the old address and what it should answer. For a redirect, that is the new address: a path on the same site or a full http:// or https:// address.

Add a redirect

  1. In the admin sidebar, under Runtime, click Redirects.
  2. Click + Add redirect.
  3. If you are signed in as a master, choose the Site.
  4. Choose a Kind. The default is Redirect. See "Pick a kind" below.
  5. In From, enter the address that is still asked for, such as /images/blog/old-photo.jpg. You can paste a full address. Only its path is kept. To answer one query string only, tick Match a query string and fill in From query. See "Match a query string" below.
  6. In To, enter where visitors go: a path on this site, such as /uploads/site/media/photo.jpg, or a full http(s) address. For a rewrite, only a path on this site is allowed. The box is hidden for Gone (410) and Not found (404). If a visitor's request carries a query string and To has none, the query string is added to the target of a rule on a path.
  7. For a redirect, choose a Status. The default is 301 Moved permanently.
  8. Leave Active ticked and click Create. The page answers Redirect created. To leave a note for your team, open Add a note and fill in Description first.

the redirect form open over the list, with From "/plans", To "/pricing", Status "301 Moved permanently", Active ticked and the Create button visible

The form asks for the old address, the new one and the status.

The list shows each rule as the old address with the new one under it, then its Kind, its Status for a redirect, whether it is Active, and, for a master, its Site. The search box looks in the old address, the query, the new address and the description. You can also filter by Kind, Status and Active.

Pick a kind

KindWhat the visitor gets
RedirectThe browser is sent to To with the Status you chose.
RewriteThe address stays as it is in the browser, and the page or media file at To is served there with a 200. To is a path on this site with no query. The CMS's own addresses are refused, and a file must be one of the site's own media files under /uploads/<site>/media/. The target is served as it is and never looked up again, so a rewrite cannot loop.
Gone (410)The site's error page for 410. See Customize error pages.
Not found (404)The site's error page for 404.

A rewrite, a 410 and a 404 answer only while the site is open. A rewritten file is sent with no-cache, so a change to the rule shows at once.

Pick a status

StatusUse it when
301 Moved permanently or 308 PermanentThe move is for good. A browser and a search engine treat the new address as the page's address. 301 Moved permanently is the default.
302 Found or 307 TemporaryThe move is temporary and the old address comes back later.

The status applies to the Redirect kind only. The list marks permanent moves (301 and 308) in blue and temporary ones (302 and 307) in amber.

What a rule matches

  • An exact path. A rule has no wildcards. /old-page matches /old-page and /old-page/.
  • Any query string, unless the rule names one. The address is stored without its query string or fragment, so /old-page?ref=news matches a rule that has no From query.
  • Before the page. The CMS checks the rules as soon as it knows the site, before it looks for a page. A rule therefore answers a page that moved and a file that is no longer there.
  • One rule per address and query. A second rule for the same From and the same From query on a site is refused with This site already redirects that address. The same From with another From query is allowed. An archived rule does not hold its address.
  • Repeated slashes. A GET or HEAD request for an address such as //about/ is sent with a 301 to /about/, with its query kept. The CMS's own addresses are left alone.

The CMS writes the address in one form. A leading / is added, a trailing / is dropped, and escapes such as %D8%A8 are decoded. An address with a space, or with a scheme other than http or https, is refused with Enter an address on this site, such as /old-page.

Match a query string

Some old addresses differ only by their query, such as WordPress ?p=123 links. Tick Match a query string and enter the query in From query, such as p=123 or page_id=7. The CMS stores it without the ?, with its parameters sorted by name. Leave it empty to answer the address whatever its query.

For a request with a query string, the CMS asks for a rule in this order, and the first match answers:

  1. A rule on the whole query.
  2. A rule on one of the request's parameters, such as p=123 among p=123&utm_source=x.
  3. A rule on a wildcard for one parameter, such as p=*, which answers p with any value. Write a wildcard alone: p=*&cat=1 is refused with A wildcard such as p=* is a rule's whole query: write it alone.
  4. The rule on the path alone.

A rule on a query sends its target as written and passes no other parameter on. A rule on a path adds the request's query string to a target that has none.

Rules the CMS refuses

  • The CMS's own addresses. /admin, /api, /live and /phoenix, and everything under them, cannot be a From. A rule there would send the people who manage the site, and the editor's own connection, somewhere else.
  • A rule that sends an address to itself. The answer is A redirect cannot send an address to itself.
  • A loop. The CMS follows the site's other active redirect rules from your target. If they lead back to your address, or to any address already on the way, it refuses the rule with This would make a loop and names the addresses. A target on another host ends the chain.
  • A bad target. For a redirect, To must start with a single / or be a full http(s) address, and //host is refused. For a rewrite, To must be a path on this site with no query. A redirect or a rewrite with no To is refused with Enter where this rule sends or serves the address.

A chain without a loop is allowed. If /a goes to /b and /b goes to /c, a visitor to /a follows two redirects. Point /a at /c to save the hop.

A plugin can also send a record's old address on when no rule names it. See Plugin events.

Edit, switch off or remove a rule

  • Click Edit on a row, change the form and click Save Changes. The page answers Redirect updated. A rule's site cannot change. An archived rule cannot be edited until you restore it.
  • To pause a rule, untick Active. An inactive rule is kept and answers nothing. The loop check runs again when you tick it back on.
  • Click Delete and confirm to archive a rule. To archive several, tick their rows and use the bulk Archive action.
  • Click Archived in the switch above the list to see archived rules. Restore brings one back, and Delete permanently removes it for good.

A saved change reaches every server at once, with no restart.

Check that it works

Request the old address and read the response. For a redirect, the status is the one you chose and the location header holds the new address. A rewrite answers 200 with the target's content, and a 410 or 404 rule answers that status.

bash
curl -I https://example.com/plans

A browser and a search engine treat a 301 or a 308 as final. While you test, set the status to 302 Found, and change it to 301 Moved permanently when the rule is right.

Example: a renamed pricing page

  1. You changed the page path from /plans to /pricing.
  2. Click + Add redirect. Set From to /plans and To to /pricing.
  3. Leave Status on 301 Moved permanently and Active ticked, then click Create.
  4. Run curl -I on /plans and check for the 301 and the location header.

the list with the rule "/plans" to "/pricing" in the first row, a blue 301 Moved permanently badge and an Active badge

The saved rule appears at the top of the list.

Next steps