Store the routes for your redirects in a
ROUTER file in the root of your project (no file extension necessary).
ROUTER files are part of Surge Plus. When you publish, you’ll be prompted to upgrade your project right from the CLI.
You can make this file using your favourite text editor, or right from the command line using:
Now, you can setup custom redirects within this file. There are three pieces of information required, all on the same line:
- The type of redirect, determined using the HTTP status code
- The original URL pattern you’d like to redirect
- The new URL pattern you’d like to redirect to
A basic example:
301 /contact /about
Now, your old Contact page URL page will automatically redirect to your About page.
This example redirect has a 301 status code, which is a permanent redirect. The options for this are:
|Status Code||Redirect Type|
What if you don’t just have one redirect to make, but many? You may also add a redirect pattern, which will catch and redirect all URLs following a certain format. For example:
301 /my-blog/:title /articles/:title
Now, any post previously under
/my-blog/my-first-post, will be redirected to
:title is used in this example, but you can name the pattern variables anything you’d like. Here’s how you might redirect the URLs from an old WordPress blog to your new static Jekyll site:
301 /:year/:month/:day/:slug /blog/:slug
You can also redirect to a different URL altogether:
307 /blog https://medium.com/surge-sh
If you’d like to add additional redirects, you can put one on each line.
301 /:year/:month/:day/:slug /blog/:slug 301 /contact /about 307 /code http://github.com/surge-sh