· Tutorial ·

Redirect from www to non-www or the other way round via .htaccess

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 have to apply this change in the .htaccess file.

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

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

Second option ⇾ In your SWPanel, you have a File Manager with which you can manage and administer the directories and files of your Web. You can guide you with the following manual

The ".htaccess" file is hidden. If you don't see it, you should enable the option to view hidden files in your FTP client. You may also need to create it. ⚠️

Next, add the lines of code we specified:

REDIRECT DOMAIN WITH NO 'WWW'

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

REDIRECT DOMAIN WITH 'WWW'

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

REDIRECT DOMAIN INDISTINCTLY WITH 'WWW' or WITHOUT 'WWW' - HTTPS

This example can be given in the case you have an SSL certificate installed on a www.dominio.com and you would like to redirect all domains, both www and non-www domains, to https://www.dominio.com.

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

i