Redirecting Www To Non-www Domains On Nginx And Apache

Posted by Weston Ganger on September 01, 2015

Redirecting a www address to a non-www address or vice versa is important for SEO. Heres how to set it up on Nginx and Apache in the most efficient way.

# Nginx - Redirect www to non-www
server {
  return 301 $scheme://$request_uri;

# Apache - Redirect www to non-www
  <IfModule mod_alias.c>
    Redirect permanent /

If you need to do non-www to www then just change the above code to suit the need.

Related External Links:

Posted in Linux and Tagged with nginx apache webserver redirect 301 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts