Q:

Redirection and replacement with Nginx

I am having trouble getting this to work in nginx:
I am trying to rewrite, a url string like this to this:
http://domainname/n/xxx = > http://domaindomain/x/xxx

I would like only "n" to change to "x"
I have tried :
location  /n/ {
    rewrite ^/n/(.*)$ /x/? last;
}

Thanks for the help

A:

You need to use the following rule:
rewrite ^/n/(.*)$ /x/$1 permanent;

(.*) will capture your URL after the /n/ part and $1 will place the same thing in the target URL.
Using the permanent keyword will redirect the users with a 301 HTTP status code

