Report this

What is the reason for this report?

Need help with page redirect on Nginx

Posted on January 25, 2020
Sai

By Sai

Hi all,

I’m struggling with a redirect issue. I need to redirect a specific page to another due to naming changes.

www.example.com/blogs to www.example.com/blogs/all

Just need to set a permanent redirect for the above example. I’ve set this in default .conf file in many different ways but nothing works.

Tried rewrite, return, permanent ways in server block but didn’t help.

There is already a server block in .conf file that was added for http to https redirect. Not sure if there should be only one server block or something.

Created a redirects.conf file as well and tried but nothing works. Any help will be greatly appreciated!



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!

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.

Hi @saipradyz,

You need to set the rewrite of your page in your server block in the .conf file of the domain.

This is how a permanent redirect from a page to another one looks like

server {
# Permanent redirect to an individual page
rewrite ^/blogs http://www.example.com/blogs/all permanent;
}

Please note you need to have a separate configuration file for your domain -

/etc/nginx/sites-available/domain.com.conf
/etc/nginx/sites-enabled/domain.com.conf

Regards, KDSys

Hi,

I have the same problem as you. I’ve tried everything you did and everything I found online and no success. What could have been wrong?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.