How to Remove WWW From a Website Address
When setting up a website, one of the small but important technical details is choosing a preferred domain version — with or without “www”. From an SEO perspective, this decision matters because search engines may treat these versions as separate URLs if they are not properly configured. This can lead to duplicate content issues, split ranking signals, and weaker overall visibility in search results. By selecting a canonical version and redirecting the alternative, you ensure that all traffic and authority are consolidated under a single domain. In this article, we will look at how to remove “www” from a website address and configure it correctly.
But before making changes to the server configuration files, check the possibility of such a setting through the interface of your hosting. I have come across hostings where removing www from the site address is done in the hosting administration panel. And changes to the files (.htaccess or NGINX config) directly do not lead to anything and are ignored. This does not happen often, but it does happen.
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:
-
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...
-
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...
-
Internal Linking on Websites
Internal linking refers to the practice of connecting pages within the same website using hyperlinks. This strategy plays a crucial role in both search engine optimizatio...
Leave a Reply