Location for rewrite rules


#1

what is the suggested file to add/edit for nginx rewrite rules.

for instance, if i want to make sure anyone who hits the url /old gets redirected to url /new what would I add as the rewrite and in which file?


#2

I put my rewrite rules in /var/www/example.com/conf/nginx/rewrites.conf (this file doesn’t exist by default, one must create it).

I use the following rule for redirection:

location ~ /old {
    rewrite ^/old/(.*)$ http://example.com/new/$1 permanent;
}

This will produce a 301 redirect; if you want a 302 instead, replace permanent with redirect on the code above.


#3

i like that idea! thanks.


#4

Hi @datagroove

I hope your query is resolved. I am closing this support topic for now.

Feel free to create a new support topic if you have any queries further. :slight_smile:


#5