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
Similar posts:
-
Configuring HTTPS for Nginx
HTTPS stands for Hypertext Transfer Protocol Secure, and it is the secure version of HTTP, the protocol used for communication between your web browser and a website. HTT...
-
Internal Linking on Websites: SEO Benefits and User Experience
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...
-
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...
Leave a Reply