Scroll

Web site redirection

Recently, we have many requests regarding links redirection. Frequently task looks like: "I have web site and it is located on domain.com. How to make that when visitor opens www.domain.com, domain.com will be opened instead? "

The most effective method is to configure .htaccess file, which is located in web site's root directory.

You should open .htaccess file in any text editor (for example NotePad++), then you should edit file like it is shown in example below:

RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA]

In case, if your template located in sub-folder (and web site's URL looks like http://domain.com/Subfolder/), then .htaccess file should look like this:

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA]

In similar way you can set redirection to www.domain.com

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

Redirect HTTP to HTTPS automatically

If you have a secure certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) version of your website

Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

If you have an existing .htaccess file:

  • Do not duplicate RewriteEngine On.
  • Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.
Have more questions? Submit a request

Comments

Powered by Zendesk