Location for rewrite rules

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?

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.

2 Likes

i like that idea! thanks.

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: