Skip to content

Commit c687663

Browse files
authored
fix: Solve an issue where rewrites due to APPEND_SLASH_FOR_POSSIBLE_DIRECTORY would cause duplication of the query string (#209)
# What As reported here #205 when * `APPEND_SLASH_FOR_POSSIBLE_DIRECTORY=true` * `ALLOW_DIRECTORY_LIST=false` * `PROVIDE_INDEX_PAGE=true` Are set, requests containing query strings without a trailing slash were being duplicated (`foo?a=b` were becoming `foo?a=b?a=b`). ## Cause The `rewrite` directive will automatically append the query string unless a final trailing `?` is supplied. This was causing the duplication ## Fix Added an explanatory comment and a trailing `?` to the rewrite rule to prevent automatic appending of the query string as we already do it in the argument to the rewrite rule. I chose to do this rather than depending on the default behavior of `rewrite` since the rule as it is expressed is more explicit. The trailing `?` is mysterious and so a comment was included to clarify.
1 parent f6dfdc9 commit c687663

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

common/etc/nginx/templates/default.conf.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ server {
332332

333333
location @trailslash {
334334
# 302 to request without slashes
335-
rewrite ^ $scheme://$http_host$uri/$is_args$query_string redirect;
335+
# Adding a ? to the end of the replacement param in `rewrite` prevents it from
336+
# appending the query string.
337+
rewrite ^ $scheme://$http_host$uri/$is_args$query_string? redirect;
336338
}
337339

338340
# Provide a hint to the client on 405 errors of the acceptable request methods

0 commit comments

Comments
 (0)