301 redirect nginx

Posted May 12, 2014 69.2k views
Hello! I need 301 redirect from to
1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
5 answers
You can use a rewrite rule, like so:

rewrite ^/category/something/(.*)$$1 redirect;

And remember to restart nginx:

service nginx restart

Check out this article:
by Justin Ellingwood
HTTP redirects are used to redirect web site visitors to new locations when they request content. These are useful for a variety of reasons, whether permanent or temporary. This guide will demonstrate how to redirect visitors using Apache and Nginx.
Thanks for answer but i have 404
Sry, works great, thanks!

Hi admin
I want change old a URL
I using nginx. Thank you so much

server {
listen 80;
rewrite ^(.*)$1 permanent;
rewrite ^/du-an(.*) https://$server_name/category/du-an/$1 permanent;
server {
    listen       443 ssl http2;
    return       301$request_uri;
    rewrite ^/du-an(.*) https://$server_name/category/du-an/$1 permanent;
ssl_certificate /etc/nginx/paidssl/;
ssl_certificate_key /etc/nginx/paidssl/;

and then service nginx restart

Check nginx
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Please help me. Thank you so much