Skip to main content

Redirects

Write redirects in settings/redirects.php, one array per redirect. TONKATSU runs them, and nothing is stored in the database. Don't use a redirect plugin or write them in .htaccess.

// settings/redirects.php
return [
['from' => '/old-page/', 'to' => '/new-page/'], // Exact match, 301
['from' => '/old-dir/', 'to' => '/new-dir/', 'type' => 'prefix'], // /old-dir/a/ → /new-dir/a/
['from' => '^blog/(\d+)$', 'to' => '/news/$1/', 'type' => 'regex'], // Regular expression
['from' => '/campaign/', 'to' => 'https://example.com/', 'status' => 302],
['from' => '/closed/', 'status' => 410], // Gone, shown with the 404 template
];
  • status is 301 (default), 302, 307, 308 or 410.
  • They are matched in this order: exact → prefix (longest first) → regular expression (in the order written). The query string is carried over.
  • A regular expression is matched against the path without its leading and trailing slashes. Check that it doesn't also match existing pages: ^news/(\d+)$ would catch posts whose slug is a number.
  • Redirects stop while another SEO plugin such as Rank Math is active.

Checking the redirects​

Redirects in Tools → SEO (TONKATSU) lists them. It warns about a redirect that hides a page in settings/pages.php and about chained redirects.

To log the redirect hits, set logRedirects: true in settings/seo.php (off by default). The hit counts and the log then appear on the same screen. Each hit is kept for redirectLogDays days (90 by default); no IP address or user agent is stored.

See the RedirectConfig documentation for the details.