Automatic redirects (trailing slash) ignore root_path, breaking deployments behind reverse proxies with path prefixes
#14284
Replies: 1 comment
-
|
You should configure your proxy not to strip prefix from the path when you pass Alternatively, use Current version of docs is incorrect, I've been working on the PR to fix this: #14238 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Description
When FastAPI is deployed behind a reverse proxy with a path prefix (common pattern), automatic redirects for trailing slash normalization do not include the
root_pathprefix, resulting in broken redirects.Deployment scenario:
Expected Behavior
Automatic redirects should include
root_path, just like explicit redirects usingrequest.url_for()do:Actual Behavior
Automatic redirects ignore
root_path:The
URLclass (starlette/datastructures.py) only readsscope["path"]and never readsscope["root_path"]:Meanwhile,
Request.url_for()correctly usesroot_pathviaRequest.base_url:Beta Was this translation helpful? Give feedback.
All reactions