nginx rewrite rules for website and blog changes

  • Posted June 11, 2013

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
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.

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! :]

I’ve tried that and it was not working for. I actually couldn’t get anything to work other than the redirect 301 to redirect to I’ve tried rewrites and location rewrite blocks and none work. Is there an additional step to take to enable rewrites in nginx its like they are disabled or the module isn’t installed? <br> <br>Anybody else having redirect issues with stock nginx in the Ubuntu 12.04 32bit?

You can redirect to and* to - are you okay with that?