How to Remove WWW From a Website Address
Last updated: 26.10.2025
Views: 310
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
Similar posts:
-
Why Website Loading Speed Matters for SEO
Website loading speed plays a crucial role in modern SEO strategies. Search engines like Google prioritize websites that offer fast and smooth user experiences. A slow-lo...
-
How to Run (Deploy) a Single Page Application (SPA) on Shared Hosting
Building modern websites with Vue or React has become the standard practice in web development. However, when you try to deploy a Single Page Application (SPA) to a regul...
-
Protecting a Website or Directory with a Password Using .htaccess and .htpasswd
Securing a website or a specific directory with a password is a simple yet effective way to restrict access. This can be done using .htaccess and .htpasswd files in Apach...
Leave a Reply