Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

if have url like https://domain.com/print?sitepath=/news.html and i have nginx config to…

  1. User

    if have url like https://domain.com/print?site_path=/news.html and i have nginx config to redirect old urls like that to /news.html rule in config:

    location /print { return 301 $arg_site_path; }

    but i get infinite redirects to the same url. what is wrong?

  2. Assistant

    The infinite redirect loop occurs because the redirected URL still matches the /print location block, and hence NGINX keeps applying the redirect rule repeatedly. To prevent this, you need to ensure that the rule only applies to requests that contain the site_path argument and not the final destination URLs such as /news.html.

    You can do this by adding a condition to check if the site_path argument exists. Here is how you can modify your configuration:

    location /print {
        if ($arg_site_path) {
            return 301 $arg_site_path;
        }
    }
    

    Alternatively, you may want to add a rewrite rule to handle this more globally:

    location /print {
        rewrite ^/print$ $arg_site_path permanent;
    }
    

    In this second example, the rewrite rule will only be applied if there are no additional URI components past /print, which helps avoid any redundant processing.

    These modifications ensure that once the redirection is made, the new URL no longer matches the /print location block, thus preventing the infinite redirection loop.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.