You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The netlify plugin allows you to add redirects programmatically. It does differentiate between permanent and non-permanent redirects (status code 301 or 302) but does not allow any other values.
Netlify redirect rules are as follows:
FROM TO STATUS_CODE[!] [key1=value1] [key2=value2]
The plugin allows you to set all of these except the status code:
FROM is set with fromPath
TO is set with toPath
The exclamation mark is set with force
Key value pairs are also supported
But the only way to control the status code is to get it to switch from 301 to 302 by setting isPermanent to true.
Given that this is a netlify-specific plugin, and Netlify supports plenty of status codes, I feel there should be a way to handle this through the plugin. The most common use-cases are:
Set status code 200 for rewrites (instead of redirects)
redirects=redirects.map(redirect=>{const{
fromPath,
isPermanent,
redirectInBrowser,// eslint-disable-line no-unused-vars
force,
toPath,
...rest}=redirectletstatus=isPermanent ? `301` : `302`if(force)status=status.concat(`!`)// The order of the first 3 parameters is significant.// The order for rest params (key-value pairs) is arbitrary.constpieces=[fromPath,toPath,status]
I would propose to add a statusCode that (if it's set) would take precendce over the isPermanent setting. Something like this:
redirects=redirects.map(redirect=>{const{
fromPath,
isPermanent,
redirectInBrowser,// eslint-disable-line no-unused-vars
force,
toPath,
statusCode,
...rest}=redirectletstatus=isPermanent ? `301` : `302`if(statusCode)status=statusCodeif(force)status=status.concat(`!`)// The order of the first 3 parameters is significant.// The order for rest params (key-value pairs) is arbitrary.constpieces=[fromPath,toPath,status]
Motivation
If statusCode defaults to FALSE this wouldn't break anything for existing users, yet allow people to use this plugin to fully leverage the Netlify redirects/rewrites system.
Not to mention that unless I'm missing something, this is a rather small change.
The text was updated successfully, but these errors were encountered:
joostdecock
changed the title
gatsby-plugin-netlify Does not support rewrites, or setting a different status code
gatsby-plugin-netlify does not support rewrites, or setting a different status code
Jan 24, 2019
I am.
The entire mono-repository lerna thing which is new to me. But I'll try to find some time to read up on how development is handled in the Gatsby repo and see if I can get a PR together. Would be nice to learn some new stuff :)
Summary
The netlify plugin allows you to add redirects programmatically. It does differentiate between permanent and non-permanent redirects (status code 301 or 302) but does not allow any other values.
Netlify redirect rules are as follows:
The plugin allows you to set all of these except the status code:
FROM
is set withfromPath
TO
is set withtoPath
force
But the only way to control the status code is to get it to switch from 301 to 302 by setting
isPermanent
totrue
.Given that this is a netlify-specific plugin, and Netlify supports plenty of status codes, I feel there should be a way to handle this through the plugin. The most common use-cases are:
Basic example
Redirect creation is handled here as such:
I would propose to add a
statusCode
that (if it's set) would take precendce over theisPermanent
setting. Something like this:Motivation
If
statusCode
defaults toFALSE
this wouldn't break anything for existing users, yet allow people to use this plugin to fully leverage the Netlify redirects/rewrites system.Not to mention that unless I'm missing something, this is a rather small change.
The text was updated successfully, but these errors were encountered: