caddy: URL rewrite performing 301 redirect
1. What version of Caddy are you using (caddy -version)?
0.10.4
2. What are you trying to do?
Rewrite incoming URLs, so assets are served correctly and everything else resovles to index.html.
3. What is your entire Caddyfile?
:5000, https://redacted.domain {
root /src/dist
tls {%CADDY_TLS_SETTING%}
rewrite /revision {
to REVISION
}
rewrite / {
regexp .*
to {path} /index.html
}
gzip
log stdout
errors stdout
}
4. How did you run Caddy (give the full command and describe the execution environment)?
In Docker:
CMD ["caddy", "--conf", "/src/Caddyfile", "--log", "stdout"]
5. Please paste any relevant HTTP request(s) here.
Curl:
curl -Ik https://redacted.domain/people
HTTP/1.1 301 Moved Permanently
Content-Type: text/plain; charset=utf-8
Date: Fri, 30 Jun 2017 08:55:09 GMT
Location: /
Server: Caddy
Connection: keep-alive
Access log:
2017-06-30T09:00:09Z web:RQKEUGQPVAP/22508fd20d03 10.0.1.144 - - [30/Jun/2017:09:00:09 +0000] "GET /people?as HTTP/1.1" 301 63
2017-06-30T09:00:09Z web:RQKEUGQPVAP/22508fd20d03 10.0.1.144 - - [30/Jun/2017:09:00:09 +0000] "GET /?as HTTP/1.1" 200 683
2017-06-30T09:00:13Z web:RQKEUGQPVAP/22508fd20d03 10.0.2.46 - - [30/Jun/2017:09:00:13 +0000] "GET / HTTP/1.1" 200 683
6. What did you expect to see?
Caddy is serving a static SPA, so we expected that the page corresponding to /people in the app would render. This is what happens in 0.10.3 and is confirmed by reverting to that version of Caddy.
7. What did you see instead (give full error messages and/or log)?
Caddy redirects all of the requests to /.
8. How can someone who is starting from scratch reproduce the bug as minimally as possible?
Build a minimal frontend app that rewrites all requests to index.html and uses client-side routing to decide what to render on the client.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (7 by maintainers)
Hey @leemachin, thanks for taking the time to fill out the issue template!
This is expected behavior. Your rewrite rule is telling Caddy to rewrite all requests to the same path (if it exists on disk) or, if not, to /index.html.
If the path is rewritten to /index.html, the static file server issues a redirect to canonicalize the path to /, which is correct for serving index files.
If you change your rewrite rule to:
then it will not issue the redirect anymore, since the rewritten path is correct this way.
Hope this helps!
@mkhennoussi please ask your usage questions at https://caddy.community. This is the issues board for bugs and feature requests.
@dtrinh100 Make sure to clear your browser cache; check it with curl just to be sure!
@leemachin
Commit f4b6f15e07b91976d6579c8445a3321dcc63d8ae.
It fixed a regression. 😉