Canonical Rewrite Rule For Nginx

Need to redirect from acme.com to www.acme.com with nginx? No problem … just add a virtual host declaration for the non-www that redirects like this:

or if you want to add to an existing vhost:

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

3 Responses

    1. The virtual host should be placed in the nginx.config files. Exactly which file depends on how nginx is setup on your server. For example you might have a file like /etc/nginx/sites-enabled/mydomain.conf where your primary domain is defined. This would be a good place to add the rewrite rules.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.