Skip to content

Commit 154a497

Browse files
B4nanclaude
andauthored
fix(nginx): add general redirect to remove trailing slashes (#2225)
Adds a location block to remove trailing slashes from all URLs (except root /). This fixes the 404 error when accessing URLs like /api/v2/ with a trailing slash. Uses a regex location block instead of a rewrite rule for clearer processing precedence. Exact match locations (e.g., location = /sdk/js/) take priority over this regex, so existing handlers are unaffected. Slack thread: https://apify.slack.com/archives/C0L33UM7Z/p1770281199186039 https://claude.ai/code/session_01GqcrG6JU9Y1YaSA5ns87Yz <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Simple Nginx routing change; main risk is unexpected redirects for endpoints that intentionally rely on trailing slashes. > > **Overview** > Adds a global Nginx `location` regex that **redirects any non-root URL ending in `/` to the same path without the trailing slash**. > > This prevents 404s for requests like `/api/v2/` while keeping explicit exact-match locations (e.g., `location = /sdk/js/`) higher priority than the new catch-all redirect. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 99d352c. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent dd83eaf commit 154a497

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

nginx.conf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ server {
3434
proxy_pass $backend$uri;
3535
}
3636

37+
# remove trailing slashes from all URLs (except root /)
38+
# exact match locations (e.g., location = /sdk/js/) take priority over this regex
39+
location ~ "^(.+)/$" {
40+
return 301 $1$is_args$args;
41+
}
42+
3743
location / {
3844
set $rewrite_condition "$serve_markdown$has_no_extension";
3945
set $proxy_path $request_uri;
@@ -460,9 +466,6 @@ server {
460466
rewrite ^/sdk/python/$ /sdk/python redirect;
461467
rewrite ^/cli/$ /cli redirect;
462468

463-
# remove trailing slashes from all other URLs (except root /)
464-
rewrite ^(.+)/$ $1 redirect;
465-
466469
# versions page redirects
467470
rewrite ^/versions/?$ / permanent; # no docs-wide changelog, redirect to the root
468471
rewrite ^/cli/versions/?$ /cli/docs/changelog permanent;

0 commit comments

Comments
 (0)