I’m just set up Caddy and am planning to use it as a lean solution to 301 redirect 50,000 subdomains to directories on my server.
I have a few questions about my Caddyfile:
- How do I make redir a 301 instead of a 302-- is it simply “redir 301”?
- Do I really need to add separate www and non-www versions for each redirect, or is there a way to do this with a rewrite?
- Are there any best practices for doing this I should know about?
- Is there a way to redirect any other subdomains (wildcard) not covered in this file to my homepage?
- Is there a way to redirect all 404 errors to the homepage?
Note that I am forcing http since I have so many subdomains and am redirecting them to a https address anyway.
d. My complete Caddyfile or JSON config:
http://macfans.xx.yy {
redir https://xx.yy/apple
}
http://www.macfans.xx.yy {
redir https://xx.yy/apple
}
http://election2020.xx.yy {
redir https://xx.yy/politics
}
http://www.election2020.xx.yy {
redir https://xx.yy/politics
}
http://iphonerumors.xx.yy {
redir https://xx.yy/apple
}
http://www.iphonerumors.xx.yy {
redir https://xx.yy/iphone
}
I am grateful for any insight the community has in this. I came across Caddy after another sysadmin recommended it as a lean solution for processing a high volume of 301s.