Question

301 redirect nginx

Hello! I need 301 redirect from site.com/category/something to site.com/something/

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

You can use a rewrite rule, like so: <br> <br><pre> <br>rewrite ^/category/something/(.*)$ http://site.com/something/$1 redirect; <br></pre> <br> <br>And remember to restart nginx: <br> <br><pre> <br>service nginx restart <br></pre> <br> <br>Check out this article: <br> <br>https://www.digitalocean.com/community/articles/how-to-create-temporary-and-permanent-redirects-with-apache-and-nginx

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

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

Hi admin I want change old a URL https://www.bandatnendongnai.vn/du-an/ New URL https://www.bandatnendongnai.vn/category/du-an/ I using nginx. Thank you so much