Remove www in the site address, 301 redirects

A redirect is to redirect site visitors from one URL to another. 301 status indicates that the redirect is permanent. Removing www from the site address is necessary primarily for SEO. Since sites with www and without for search engines are different sites with the same content.

For Apache server, you need to make an entry in the .htaccess file

RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

For NGINX, write in the site configuration file

if ($host ~* www\.(.*)) {
    set $host_without_www $1;
    rewrite ^(.*)$ http://$host_without_www$1 permanent;
}

$host_without_www - write like that, this is a server variable

Comments

Popular posts from this blog

JavaScript Inheritance and Classes

Typical gulpfile.js

Swipe events on touch devices