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 issue you're experiencing is due to the fact that the NGINX configuration redirects every request under the /print location back to the URL specified in the query parameter site_path, which means that it will keep redirecting any request to /print?site_path=/news.html back to /print?site_path=/news.html instead of /news.html.

    To fix this issue, you need to ensure that the redirect only happens if the query parameter site_path is not referencing the /print location. You can use a condition to check this.

    Here is an updated NGINX configuration to solve this problem:

    location /print {
        if ($arg_site_path ~* "^/print") {
            break;
        }
        return 301 $arg_site_path;
    }
    

    This configuration uses an if statement to check if the site_path argument contains /print. If it does, it breaks out of the location block, effectively stopping further processing of the request and preventing infinite redirection. If it doesn't, it proceeds with the redirection.

    Please reload or restart your NGINX server after making this configuration change to apply it.

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