Rewriting URLs with Nginx

Rewriting URLs with Apache HTTPD can be pretty ugly. With Nginx it is a breeze. Take a look to this example:

server {
 listen 80;
 rewrite ^/(.*)$1 permanent;

This will not just redirect your old URL to your new URL. It passes all the parameter to your new URL, too. If you are migrating a Web Application to new URL, this what you want. All old bookmarked URL are still working with this.

Published by Robert Reiz

CEO @ VersionEye. Passionated software developer since 1998.

2 thoughts on “Rewriting URLs with Nginx

  1. There is another (and probably a better) way to do the same…

    server {
    return 301 $scheme://$request_uri;

    The advantage here is the 301 that may be good for SEO. 🙂

Leave a Reply to Pothi Kalimuthu Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: