Redirect from www to non-www and vice versa via .htaccess

Atualizado em 2026-10-23 20:00:48 64 visitas

In this manual, we will explain how to redirect your domain without www to a specific URL or to the same one with www; you only need to apply this change in the .htaccess file

To perform this action, you can do it in two ways:

First option ⇾ Connect via FTP to the directory '/datos/web/' and edit the file '.htaccess'.

Second option ⇾ In your SWPanel, you have a File Manager with which you can manage and administer your website's directories and files. You can follow the following manual Manual: ##título##

⚠️ The '.htaccess' file is hidden. If you do not see it, you must enable the option to see hidden files in your FTP client. It is also possible that you may need to create it. ⚠️

Next, add the lines of code that we specify:

REDIRECT DOMAIN WITHOUT ‘WWW’

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

REDIRECT DOMAIN WITH ‘WWW’

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

REDIRECT DOMAIN REGARDLESSLY WITH ‘WWW’ or WITHOUT ‘WWW’ – HTTPS

This example may occur if you have an SSL certificate installed on a www.domain.com and if you would like to redirect all domains, both those with www and those without www, to https://www.domain.com

RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]