Technical information

301 redirect using .htaccess

Here you will know about possible ways to set 301 redirect by .htaccess file. To change .htaccess file, perform the following steps:

If there is no such file, create it.

301 redirect from HTTP domain to HTTPS domain

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]

301 redirect from WWW domain to domain without WWW

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

Enter the domain of your website instead of ‘site.com’.

redirect from domain without WWW to WWW domain

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

301 redirect from one domain to another

RewriteEngine On
RewriteCond %{HTTP_HOST} domain1.ua
RewriteRule (.*) http://domain2.ua/$1 [R=301,L]

See also