This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to the original Chinese version. I am continuously working to improve the translation.
Here’s a brief description of the issue: When configuring redirects on Netlify, you need a _redirects file in the root directory of your project, with the redirect rules defined inside. See the full redirect rules here. If you’re building locally with hexo g, you can simply place this file in the public folder and push it directly to your remote repository. However, if you’re using Netlify’s build feature, you need to configure Hexo to generate the _redirects file as part of the final site output.
I searched online for a while but couldn’t find a clear solution, and the official documentation was too brief. After quite a bit of trial and error, I finally got it working—so I’m documenting it here for future reference.
Configuration steps:
- Place your properly formatted
_redirectsfile into thesourcefolder in your Hexo root directory. - In the
_config.ymlfile at the root directory, addinclude: _redirects. (There’s likely already anincludeline—just append the filename to it.)
(Hexo ignores files starting with an underscore by default, so adding it toincludeforces Hexo to process it.) - Still in
_config.yml, addskip_render: _redirectsto prevent Hexo from rendering the file—this ensures it’s copied directly to thepublicfolder without modification. - Save the changes, then run
git add,commit, andpush—that’s it.
This article is licensed under the CC BY-NC-SA 4.0 license.
Author: lyc8503, Article link: https://blog.lyc8503.net/en/post/hexo-config-redirect/
If this article was helpful or interesting to you, consider buy me a coffee¬_¬
Feel free to comment in English below o/