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?
- 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/
- 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.
- 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]
Comments 1
If I need setup redirection, I always use this page. Thank you!