integrate with gatsby-plugin-meta-redirect, notes on server rendering

This commit is contained in:
Matthias Kretschmann 2018-08-30 16:11:52 +02:00
parent 9bd28a7e9c
commit 2cd07ee33e
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 17 additions and 4 deletions

View File

@ -13,6 +13,7 @@ By adding a list of urls to the YAML frontmatter, this plugin creates redirects
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Server Rendering](#server-rendering)
- [Usage](#usage)
- [Plugin Development](#plugin-development)
- [License](#license)
@ -31,15 +32,26 @@ Plugin assumes the default setup from [gatsby-starter-blog](https://github.com/g
```bash
cd yourproject/
npm i gatsby-redirect-from
npm i gatsby-redirect-from gatsby-plugin-meta-redirect
```
Then load the plugin from your `gatsby-config.js`:
Then load the plugin along with [gatsby-plugin-meta-redirect](https://github.com/getchalk/gatsby-plugin-meta-redirect) from your `gatsby-config.js`:
```js
plugins: ['gatsby-redirect-from']
plugins: [
'gatsby-redirect-from',
'gatsby-plugin-meta-redirect' // make sure this is always the last one
]
```
### Server Rendering
Gatsby's `createRedirect` only creates client-side redirects, so further integration is needed to get server redirects too. Which is highly dependent on your hosting, if you want to have the proper HTML status codes like `301`, Apache needs `.htaccess` rules for that, nginx `rewrite` rules, S3 `RoutingRules` and so on.
One simple way, as suggested in installation, is to use [gatsby-plugin-meta-redirect](https://github.com/getchalk/gatsby-plugin-meta-redirect) to generate static HTML files with a `<meta http-equiv="refresh" />` tag for every `createRedirect` call. So it works out of the box with this plugin without further adjustments.
This way is the most compatible way of handling redirects, working with pretty much every hosting provider. Only catch: it's only for usability, no SEO-friendly `301` redirect is set anywhere.
## Usage
In your Markdown file's YAML frontmatter, use the key `redirect_from` followed by a list:

View File

@ -30,7 +30,8 @@
"release-it": "^7.6.0"
},
"peerDependencies": {
"gatsby": ">=2"
"gatsby": ">=2",
"gatsby-plugin-meta-redirect": ">=1.1.0"
},
"engines": {
"node": "^10.0.0"