如何让重定向链在 Netlify 中工作?
How to get a redirect chain working in Netlify?
我的 netlify 目录结构中有一个 _redirects
文件
/
- site
-- _redirects
_redirects
https://example.netlify.com/ https://www.example.com/:splat 301!
https://www.example.com/post/196 https://www.example.com/comic/post-name
问题:
第一次重定向成功,但第二次重定向 returns:
Page Not found
我已按照 https://www.netlify.com/docs/redirects/ 中的文档进行操作,但找不到导致此问题的原因。
我注意到文档中提到的 2 个潜在原因:
You can also add redirect rules to your netlify.toml file.
^^ 我没有试过这个,但是因为它显示 "also" 我认为使用 _redirects
文件应该足够了。
For Jekyll, this requires adding an include parameter to
config.yml.)
^^ 据我所知,我没有使用 Jekyll,但我的项目确实包含一个 config.yml
文件。
您将无法根据文档阅读的内容在 Netlify 上链接重定向。
The redirect engine processes the first matching rule it finds, so more specific rules should be listed before more general ones
https://example.netlify.com/post/196 https://www.example.com/comic/post-name
/post/196 /comic/post-name
https://example.netlify.com/* https://www.example.com/:splat 301!
您可以尝试不使用上面的第一行,看看 https://example.netlify.com/post/196
是否重定向到 https://www.example.com//comic/post-name
。如果它不重定向,则 Netlify 重定向中没有链接。
通过添加解决:
[[redirects]]
from = "https://www.example.me/post/196"
to = "https://www.example.me/comic/post-name"
status = 200
到netlify.toml
我的 netlify 目录结构中有一个 _redirects
文件
/
- site
-- _redirects
_redirects
https://example.netlify.com/ https://www.example.com/:splat 301!
https://www.example.com/post/196 https://www.example.com/comic/post-name
问题:
第一次重定向成功,但第二次重定向 returns:
Page Not found
我已按照 https://www.netlify.com/docs/redirects/ 中的文档进行操作,但找不到导致此问题的原因。
我注意到文档中提到的 2 个潜在原因:
You can also add redirect rules to your netlify.toml file.
^^ 我没有试过这个,但是因为它显示 "also" 我认为使用 _redirects
文件应该足够了。
For Jekyll, this requires adding an include parameter to config.yml.)
^^ 据我所知,我没有使用 Jekyll,但我的项目确实包含一个 config.yml
文件。
您将无法根据文档阅读的内容在 Netlify 上链接重定向。
The redirect engine processes the first matching rule it finds, so more specific rules should be listed before more general ones
https://example.netlify.com/post/196 https://www.example.com/comic/post-name
/post/196 /comic/post-name
https://example.netlify.com/* https://www.example.com/:splat 301!
您可以尝试不使用上面的第一行,看看 https://example.netlify.com/post/196
是否重定向到 https://www.example.com//comic/post-name
。如果它不重定向,则 Netlify 重定向中没有链接。
通过添加解决:
[[redirects]]
from = "https://www.example.me/post/196"
to = "https://www.example.me/comic/post-name"
status = 200
到netlify.toml