im@markvi.eu

In this super short note, I will show you how to redi­rect from the old-style www​.your​do​main​.com to the mod­ern your​do​main​.com.

Sim­ply add the fol­low­ing code before your Nginx domain con­fig to make the nec­es­sary changes:

server {
    listen       80;
    server_name  www.yourdomain.com;
    return       301 https://yourdomain.com$request_uri;
}

Here com­plete file view for bet­ter understanding:

server {
    listen       80;
    server_name  www.yourdomain.com;
    return       301 https://yourdomain.com$request_uri;
}

server {
        root /var/www/yourdomain.com;
        index index.php index.html index.htm;
        server_name yourdomain.com;
        location / {
                #try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        }

There are a few rea­sons why it is gen­er­al­ly pre­ferred to use a non-www domain configuration:

  1. Sim­plic­i­ty: A non-www domain is short­er and eas­i­er to remem­ber, mak­ing it more con­ve­nient for users.
  2. Con­sis­ten­cy: Using a non-www domain allows for a con­sis­tent brand expe­ri­ence across all web pages, as there is no need to wor­ry about redi­rect­ing www pages to non-www pages.
  3. SEO: Some search engines may treat www and non-www pages as sep­a­rate enti­ties, which can impact your search engine rank­ing. By choos­ing a non-www con­fig­u­ra­tion, you can avoid any poten­tial SEO issues.
  4. Improved user expe­ri­ence: A short­er and sim­pler domain can lead to a bet­ter user expe­ri­ence, as users are more like­ly to remem­ber it and return to your site in the future.

Similar Articles