zachleat/reverse-proxy-test
Redirect Tests on Netlify
_redirects file syntax test cases. Assumes that we want the trailing slash.
TL;DR
- Trailing slashes are added as expected and documented on Netlify EXCEPT when a Rewrite rule is in play. If a
200!Rewrite rule is applied to the URL, the trailing slash redirect does not apply.- 🚨
_redirectsfile entry/redirect /dir/ 200!does not add the trailing slash as expected when/redirectis requested. I believe it should 301 to/redirect/. - Is this quirk being relied on in production to workaround the trailing slash normalization? See https://flaviocopes.com/netlify-fix-trailing-slash-rewrite/
- 🚨
- Optional:
index.htmlrequests must have a separate entry in your_redirectsfile and handled manually. It would be better if/index.htmlwas normalized to/for the developer.
First test
Rewrite to another Netlify project.
_redirects Contents
/ https://a-single-html-file.netlify.app/ 200!
/dir/ https://a-single-html-file.netlify.app/ 200!
Test Results
- ✅
/is 200 - 💔
/index.htmlis 404 (want to redirect to/) - 💔
/diris 200 (want to redirect to/dir/) - ✅
/dir/is 200 - 💔
/dir/index.htmlis 404 (want to redirect to/dir/)
Second test
Rewrite to another Netlify project but with manual 301 redirects for index.html requests.
_redirects Contents
/index.html / 301!
/ https://a-single-html-file.netlify.app/ 200!
/dir/index.html /dir/ 301!
/dir/ https://a-single-html-file.netlify.app/ 200!
Test Results
- ✅
/is 200 - ✅
/index.htmlis 301 to/ - 💔
/diris 200 (want to redirect to/dir/) - ✅
/dir/is 200 - ✅
/dir/index.htmlis 301 to/dir/
Same results when Pretty URLs Asset Optimization is enabled (found at https://app.netlify.com/sites/SITE_NAME/settings/deploys).
Third test
Rewrite to local project file. Uses a /localdir/index.html local project file as a control.
_redirects Contents
/localredirect/index.html /localredirect/ 301!
/localredirect/ /localdir/ 200!
Test Results
- ✅
/localdiris 301 to/localdir/(this is what we want the rewrite request to do) - ✅
/localdir/is 200 - 💔
/localredirectis 200 (we want a 301 to/localredirect/) - ✅
/localredirect/is 200 - ✅
/localredirect/index.htmlis 301 to/localredirect/