pagehaus

Redirects

Renamed a page, or moved your site from another host? A redirect sends visitors, old links and search engines from the old address to the new page, so nobody lands on "not found" and your search rankings carry over. On every plan.

The _redirects file

Add a file named _redirects (no extension) at the top of your site, next to index.html. Each line is a rule: the old address, then the new one.

# old address          new address
/about-us              /about.html
/old-pricing           /pricing.html        302
/blog/*                /posts/:splat
/news/:year/:slug      /posts/:year-:slug.html
  • The old address is a path on your site, starting with /.
  • The new address is a page on your site (/about.html), or another website (https://shop.example.com/) on the Personal and Pro plans.
  • The status is optional: 301 (moved for good, the default, and what search engines want for a renamed page) or 302 (moved for now).
  • Lines starting with # are notes, and blank lines are fine.

You can make the file in your site's Files tab (New file), upload it, or send it over SFTP or with the pagehaus tool like any other file. Visitors can't open it.

Patterns

  • * at the end of the old address matches everything after it, and :splat puts that into the new address: /blog/* /posts/:splat sends /blog/2019/hello.html to /posts/2019/hello.html.
  • :name matches one part of the path, and the same :name in the new address puts it there: /news/:year/:slug /posts/:year-:slug.html.
  • Matching ignores capital letters and a slash at the end: /About-Us/ matches /about-us.
  • A query string (?ref=newsletter) goes along to the new address, unless the new address has one of its own.
  • The first rule that matches wins, so put specific rules before patterns.

When a rule applies

A rule only applies where there's nothing else: no file at that address, or a folder without an index page. If the page is still there, visitors see the page. So a rule can't take a working page offline by mistake, and to redirect an address you remove what's there.

Inside a password-protected area, visitors see the password page first.

From a broken link, in one click

Your site's Analytics tab lists addresses visitors followed a link to but that don't exist. Next to each, Redirect this address… asks for the new page and adds the rule to your _redirects for you.

Checking your rules

A line that can't be read is skipped, and the rest keep working. Skipped lines show at the top of your site's Files tab, and in the editor when you open _redirects, with the reason. Rules that send visitors round in a circle (/a to /b, /b to /a) are pointed out by the site check your AI assistant can run, and by pagehaus check on your computer. pagehaus serve follows your rules as Pagehaus does, so you can try them before uploading.

Moving from another host

  1. List the old site's addresses: its sitemap.xml, or the pages report in Google Search Console.
  2. For each address that changes, write a rule to the page that replaced it. Many old hosts used addresses like /about-us/ where your new site has /about.html; a pattern can cover a whole section.
  3. Upload the site with its _redirects, then watch the broken links in Analytics for a few weeks.

From Apache (.htaccess): a line like Redirect 301 /old.html /new.html becomes /old.html /new.html. Pagehaus doesn't read .htaccess.

Good to know

  • Not supported: query strings in the old address (/?p=12), 200 rewrites, ! to redirect over an existing page, and conditions such as country.
  • Up to 1,000 rules and 64 KB per site.
  • If you edit sites with CraftPages, its blog's moved posts are written to _redirects, so they redirect on Pagehaus too.
  • Sites made mainly to send visitors elsewhere aren't allowed (see the terms), and redirects to other websites are checked every day against Google's list of dangerous sites.
  • To send your other domains (www.example.com) to your main one, use the Domains tab instead: see custom domains.