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;
 server_name my_old_domain.com;
 rewrite ^/(.*) https://www.my_new_domain.com/$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.

2 thoughts on “Rewriting URLs with Nginx

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

    server {
    server_name your_old_domain.com;
    return 301 $scheme://your_new_domain.com$request_uri;
    }

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

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s