nginx rewrite rules for website and blog changes

I previously had my blog urls at it has now moved to

The main website used to be at and it is now simply at the root

I have separate sites-available conf files for the main site and the blog.

I have searched high and low and cannot find anything that seems to work to redirect the incoming urls?

I’m using Ubuntu 12.04 LTS, nginx version installed is 1.1.19

Any help would be greatly appreciated!

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Awesome, glad you got it working! :]

Thanks again, I used your example and got it working with this: <br> <br> # Rewrites <br> rewrite ^/main(.)$$1 permanent; <br> rewrite ^/blog/ permanent; <br> rewrite ^/(.)/$$1/ permanent; <br> <br>I wasn’t using a if block so I’m pretty sure that’s why I had to remove the break statements.

Try these rules: <br> <br>(in’s server block) <br> <br>rewrite ^/$ permanent break; <br>rewrite ^/main(.)$$1 permanent break; <br>rewrite ^(.)$$1 permanent; <br> <br>Make sure you reload nginx. <br> <br>With this config: <br> <br>- redirects to <br>- redirects to <br>- Everything else redirects to <br> <br>Let me know how it works for you! :]