Top Nav

Canonical Rewrite Rule For Nginx

Need to redirect from to 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:

  • Like .htaccess on Apache server. What kind of file will use to config?

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