How to route root path / to /xyz in nginx?

I am using PHP based application in which i need to configure Nginx. I wanted to forward only path / to /?product_cat=top and all other request will remains same.

below is my Nginx configuration:

server {
        server_name default_server;
        listen 80;

        root /var/www/wordpress;
        underscores_in_headers on;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, PATCH';
        add_header Allow GET, POST, HEAD, OPTIONS, PATCH always;
        access_log /var/log/nginx/ecom.log json;
        error_log /var/log/nginx/ecom-error.log;

        index  index.php index.html index.htm ;
        location = / {
        return 301 /?product_cat=top;
        }
        location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        }
      location ~ / {
        #try_files $uri $uri/ =404;
        try_files $uri $uri/ /index.php$is_args$args;
    }
}

I tried above but its giving too many redirection errors.

Topic paths routing php nginx Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.