Nginx no-www to www and www to no-www
If you want your website URL with the scheme www.domain.com redirects to domain.com in NGINX
Strip www from domain name with NGINX Redirect
server {
server_name www.domain.com;
rewrite ^(.*) http://domain.com$1 permanent;
}
server {
server_name domain.com;
#The rest of your configuration goes here#
}
Add www to domain name with NGINX Redirect
server {
server_name domain.com;
rewrite ^(.*) http://www.domain.com$1 permanent;
}
server {
server_name www.domain.com;
#The rest of your configuration goes here#
}
As you can note, this is exactly the opposite, and will not bring SEO mark downs, as it is a complete redirect and move. The no-www way is forced and the directory shown.
Written by Wilbur Suero
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Nginx
Authors
reiaguilera
279.6K
jamesdullaghan
90.19K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#