301 web page, website, and domain name redirect

With a 301 redirect you can have just about any location move to another. Here we will list how to add a 301 redirect for the most popular ways. 301 redirects can help SEO by making all access to your website hava a www. or not. This is said to tell Google to put all your page rank on one URL. Also if a page has moved and has a good ranking Google might even move that rank juice to your new url with a 301 redirect for that page to the new one.

Redirect individual files

To redirect individual files, like example.com/oldfile.htm to newfile.htm you can use a 301 redirect like this:

Redirect 301 /oldfile.htm /newfile.htm

To redirect one specific file to another domain such as example.com/oldfile.htm to example.net/newfile.htm:

Redirect 301 /oldfile.htm http://example.net/newfile.htm

Redirect an old domain to a new domain

If you had an old domain such as example.com, and now you decided you actually want to use example.net for the website. You could setup a 301 redirect for the entire domain, so that old links to example.com carry over.

Code in the example.com domain's .htaccess file:

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

Force www. version of domain to be used

A search engine like Google would see example.com and www.example.com as essentially two separate websites. They recommend you pick one version you'd like search engines to display and using a 301 redirect is a possible option.

If you have a lot of links on the web where people are linking to your site as example.com, but you would like your visitors to instead end up at www.example.com you can force this version of your domain with these rules:

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

Force non www. version of domain to be used

If you have a lot of links on the web where people are linking to your site as www.example.com, but you would like your visitors to instead end up at example.com you can force this version of your domain with these rules:

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

Redirect all files with certain extension

To re-direct all of one type of file to another, such as example.com/file.php to example.com/file.htm

RewriteEngine On
RewriteCond %{REQUEST_URI} .php$
RewriteRule ^(.*).php$ /$1.htm [R=301,L]

Was this answer helpful?

Also Read

What is the PHP Handler for shared web hosting accounts?

We use SuPHP on all shared servers. We do have a legacy server that uses CGI for the PHP Handler...

How to access remote MySQL?

Unfortunately we do not have remote access for MySQL. The security and load risk is too much for...

Is my information confidential?

Yes, your information is 100% confidential, we ask for the least amount of information needed to...

My PHP files are not working. What is wrong?

There are a number of reasons that your PHP files may not be working properly.Check that you have...