Setting up a 301 redirect via htaccess

The main error when promoting a website is wrong setting up of 301 redirects.
In what cases, you need to use redirection?

  1. The main page should have only one main writing. For example: http://www.beontop.ae/

All others must forward to this one. It is necessary set up a 301 redirect from http:// beontop.ae/ to http://www. beontop.ae/

  1. When we changed the URL of the page. We do this in order not to lose position or influence of external links to the old URL, so we need to do a redirect from the old URL to the new one.
  2. If we have the same page at multiple URL’S. This happens in almost all free and commercial CMS.

Setting up a 301 redirect from without www to www

Go to the FTP of your website and find the htaccess file there. If you can’t find it, then create a new one. Open this file using any text editor and insert the following lines:

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

Setting up a 301 redirect from www to without www

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

Setting up a 301 redirect to https://domain.ae/

RewriteEngine On
RewriteCond %{HTTP_HOST} !^domain\.ae$ [NC]
RewriteRule ^(.*)$ https://domain.ae/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

301 redirect from the old URL to the new one

RewriteRule ^old.html$ new.html [R=301,L]

Setting up redirect when changing domain name

If a new domain has “www”

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

If a new domain has “www”

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

If a new domain doesn’t have “www”

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

Author: Vadim Yudin is a professional Digital Marketing expert at Beontop and Darvin Studio. He drove hundreds of sites to the first page of search engines.

Comments 1

Asim 12.12.2016 at 04:24 PM

If I need setup redirection, I always use this page. Thank you!

Reply
What Do You Think About It?
whatsapp