×

THATBlog

301 Redirect, Using .htaccess To Your Advantage

Posted at Jan 18, 2007 1:29:43 PM by Taylor De Luca | Share

Taking advantage of your .htaccess file can save you in several ways when it comes to running your website. Broken links, bad browser behaviors, changing domain names and unwanted guests are problems we all face. One way to remedy these issues is to take advantage of the .htaccess file when it comes to broken links.

Within the .htaccess file you have the ablitiy to (301) redirect a broken or missing page to a new url or a replacement page at any time by using the code below. The reason this is recommended when removing or moving pages within the site is the search engines tend to keep they're links regardless of the outdated copy. Especially if your site doesn't have a high traffic rate or get spidered often. Users coming from the search engines will hit missing or broken pages and get a 404 error and thus not getting the benefit of your site or content.

Search engines as well will hit 404 errors and eventually stop spidering or penalize you for running errors on your site via missing or broken links.

Redirect Old domain to New domain (htaccess redirect)

Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
Please REPLACE www.newdomain.com in the above code with your actual domain name.

In addition to the redirect I would suggest that you contact every backlinking site to modify their backlink to point to your new website.

Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

Redirect to www (htaccess redirect)

Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com

The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Please REPLACE domain.com and www.newdomain.com with your actual domain name.

Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

Tags: SEO, Web Development, General

RECENT POSTS
Best Practices for Digital Marketing in 2022: FREE GUIDE