How to redirect 301 in nginx?

April 13, 2018 3.3k views
Nginx CentOS

Hello! I need 301 redirect from http://myweb.com/watch/fadfadf1 to http://myweb.com/watch-1/fadfadf1

Please help me. Thank you very much

2 Answers

Add the following to your server block in your site definition in /etc/nginx/sites-enabled

rewrite ^/watch/fadfadf1$ http://www.newdomain.com/watch-1/fadfadf1 redirect;

Then restart nginx with:

sudo service nginx restart
Have another answer? Share your knowledge.