简体   繁体   中英

How to redirect NGINX

I'm trying to redirect from https://support.example.com.br/ for https://support.example.com.br/?SSO=1

how do i do this through nginx? my code is like this:

server {
    listen 8080;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    location / {
        rewrite ^/$  /?SSO=1$1 redirect;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SERVER_NAME $host;    
    }
    location ~ /\.ht {
        deny  all;
    }
    location ~ php-errors\.log$ {
        deny all;
    }
}
server {
  ...

  rewrite ^/$ /?SSO=1 permanent;
}

Please, do not ask second, third and so on questions about the same problem. Use the comments system to clarify your problems with the particular answer. To prevent a redirect when the SSO query argument already specified in request, try this:

server {
    ... # global server block directives

    if ($arg_SSO = '') {
        rewrite ^/$ /?SSO=1 permanent;
    }

    ... # your locations goes here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM