You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation pages return 404 when the URL contains query parameters #720
Query parameters should be ignored when resolving pages: a URL with query parameters should serve the same page as the URL without them.
Impact
External services (e.g. ChatGPT, ad campaigns) link to our documentation with UTM query parameters, and their users land on an error page instead of the documentation.
The bug comes from how rack-rewrite matches rules: Rack::Rewrite::Rule#matches? runs the pattern against PATH_INFO + ? + QUERY_STRING (build_path_from_env in rack-rewrite-1.5.1/lib/rack/rewrite/rule.rb). So for /databases/index?query=x, the lambda receives match[1] == "databases/index?query=x":
File.exist?("_site/databases/index?query=x.html") → false, so the extensionless branch is taken and the target is /databases/index?query=x.
Rule#apply! splits the target at ? and sets PATH_INFO = "/databases/index" — without the .html suffix the rule exists to add.
rack-jekyll's FileHandler#get_filename only tries _site/<path> and _site/<path>/index.html — never _site/<path>.html. /databases/index resolves to nothing → 404.
This also explains the non-uniform behavior reported:
Without a query string, the File.exist? check succeeds (e.g. _site/databases/index.html) → rewritten to the .html file → 200.
/?utm_source=... works by accident: the rule captures ?utm_source=..., apply! splits it off, and PATH_INFO ends up as / → _site/index.html.
/apps?test 404s for the same reason (the file is _site/apps.html, but the rule looks for _site/apps?test.html).
Proposed fix
In config.ru, build the target from rack_env["PATH_INFO"] (which never contains the query string, per the Rack spec) instead of the regex capture, and re-append the query string so downstream consumers (analytics, client-side JS) keep it:
Note: if the query string is dropped instead of re-appended, Rule#apply! sets env["QUERY_STRING"] = "", which would silently strip UTM parameters — worth avoiding given the issue mentions ad campaigns.
An alternative is to change the regex to %r{/([^?]*)} so the query string is never captured, but the branch must still re-append QUERY_STRING for the same reason; using PATH_INFO directly is simpler.
Verification
I reproduced both the bug and the fix by running the exact middleware rule against a stub _site tree with the vendored rack-rewrite 1.5.1 and rack-jekyll's FileHandler#get_filename resolution logic. Results:
Activity
gd-scalingo commentedon Nov 25, 2026
Root cause
The production stack is Puma →
config.ru(rack-rewrite 1.5.1 + rack-jekyll). The rewrite rule inconfig.ruis:The bug comes from how rack-rewrite matches rules:
Rack::Rewrite::Rule#matches?runs the pattern againstPATH_INFO+?+QUERY_STRING(build_path_from_envinrack-rewrite-1.5.1/lib/rack/rewrite/rule.rb). So for/databases/index?query=x, the lambda receivesmatch[1] == "databases/index?query=x":File.exist?("_site/databases/index?query=x.html")→false, so the extensionless branch is taken and the target is/databases/index?query=x.Rule#apply!splits the target at?and setsPATH_INFO = "/databases/index"— without the.htmlsuffix the rule exists to add.FileHandler#get_filenameonly tries_site/<path>and_site/<path>/index.html— never_site/<path>.html./databases/indexresolves to nothing → 404.This also explains the non-uniform behavior reported:
File.exist?check succeeds (e.g._site/databases/index.html) → rewritten to the.htmlfile → 200./?utm_source=...works by accident: the rule captures?utm_source=...,apply!splits it off, andPATH_INFOends up as/→_site/index.html./apps?test404s for the same reason (the file is_site/apps.html, but the rule looks for_site/apps?test.html).Proposed fix
In
config.ru, build the target fromrack_env["PATH_INFO"](which never contains the query string, per the Rack spec) instead of the regex capture, and re-append the query string so downstream consumers (analytics, client-side JS) keep it:Note: if the query string is dropped instead of re-appended,
Rule#apply!setsenv["QUERY_STRING"] = "", which would silently strip UTM parameters — worth avoiding given the issue mentions ad campaigns.An alternative is to change the regex to
%r{/([^?]*)}so the query string is never captured, but the branch must still re-appendQUERY_STRINGfor the same reason; usingPATH_INFOdirectly is simpler.Verification
I reproduced both the bug and the fix by running the exact middleware rule against a stub
_sitetree with the vendored rack-rewrite 1.5.1 and rack-jekyll'sFileHandler#get_filenameresolution logic. Results:/databases/index/databases/index?query=guillaume-test/apps?test/?utm_source=guillaume-test/nonexistent?x=1Reproduction script (rack-rewrite rule + rack-jekyll FileHandler logic)
Once the fix is deployed, the following should all return 200:
/databases/index?query=guillaume-test,/apps?test,/?utm_source=....