Ramyachinna
Ramyachinna

Reputation: 483

How should I redirect the url with parameters in nginx?

Here is my nginx.config

#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;


    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    server {
      listen 80;
      server_name www.example.com;
      rewrite_log on;

      location ~^/v1/(\d+)\.html$ {
        return 301 http://dev-ra.example.com/v1?exid=$1;
      }
    }
}

Edited Note: I want this url should be redirected http://www.example.com/v1/90943.html#featured to https://dev-ra.example.com/v1?exid=90943

Upvotes: 0

Views: 3097

Answers (1)

Emke
Emke

Reputation: 357

Try this:

rewrite ^/v1/([0-9]+).html /v1?exid=$1;

P.S the question has been answered here NGINX - url rewrite regular expression

P.S.s heres an example that will redirect to different domain using location block:

location ~ /v1/([0-9]+) {
    return 301 http://www.example2.org?exid=$1;
}

Upvotes: 1

Related Questions