code

How to Remove WWW From a Website Address

Last updated: 26.10.2025
Views: 309

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 ^(.*)$ https://example.com/$1 [R=301,L]

Replace example.com with your domain.

For NGINX, write in the site configuration file.

server {
    server_name www.example.com;
    return 301 $scheme://example.com$request_uri;
}

server {
    server_name example.com;
    # Your main server configuration here
}

Replace example.com with your domain.

This was (and is) the recommended method for NGINX. Although I once used another method in one of my projects and the redirect also worked.

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

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

author
Author: Igor Rybalko
I have been working as a front-end developer since 2014. My main technology stack is Vue.js and WordPress.

Similar posts:

Leave a Reply

Your email address will not be published. Required fields are marked *