Foto Galerie Updates

Quality Web Development Articles

By

Redirecting Your Website

This article tells you how to redirect a website or web page to another domain location or page:

Purpose for use:

• You are using optimizing the index.html page for search engines
• A web page no longer exists so you are redirecting it to a new page.
• Directing a .co.uk domain to a .com (multiple domains to one)
• Passing search engine rankings from old site to new one

You just created a new website but want to pass on the search engine rankings of the old one to the new one. What is the most effective and spider/visitor friendly method? You should use a 301 redirect.

301 redirect?

  • It is used when you want to redirect your website or web pages. The code “301″ is interpreted as “moved permanently”. After the code, the URL of the missing or renamed page is noted, followed by a space, and then followed by the new location or file name.
  • When a search engine spider requests a web page, your web server will check for an .htaccess file. The .htaccess file contains specific directions that are processed then sent
    back to the browser. In the .htaccess file create a line of code that reads like this:

    • Redirect /index.php http://blog.saltalamacchia.co.uk/index.php
    • The first “/” indicates that everything from the top level of the site down should be redirected. All current links within the search engine results from the old site will redirect to the top level of your new site. Save the .htaccess file to your root directory on your server.

A useful site to reference for creating .htaccess files is http://www.htaccesseditor.com/en.shtml

Redirecting a Web Page

The above example shows how to redirect a whole website. What if you want to just redirect a web page that you have changed but want to keep the rankings of the old page? Follow the same steps as above but write the code like this redirect 301 /old/old.htm http://www.you.com/new.htm
Note: It may take several weeks or months for the old rankings to be passed on to the new site. Therefore don’t remove your old domain name, website or web pages just yet.

Auto-Redirecting Methods

The “Meta Refresh Tag” method

This method search engines can detect. It is also the one method that the engines are perfectly happy with as long as there is a reasonable delay between landing on a page and being redirected from it. At least 5 seconds is recommended. The code for it must be in the section of the page, and looks like this:-

META http-equiv = “refresh” content = “0; URL = anydomain.com/destination.html”

Don’t forget to include the “http” protocol which has been omitted.

The “content” parameter contains two parts, separated by a semi-colon. The first part is the delay, in seconds, before the redirection occurs. The second part is the URL to redirect to which, like any hyperlink, can be a relative URL (as above) or an absolute URL.

For search engine optimization purposes, a delay in the auto-redirection is not usually desirable. Using the Meta Refresh Tag with a delay of 0 (zero) seconds is not recommended because search engines can read HTML, Meta tags are HTML, and people have had penalties from redirecting that way. For an immediate redirect, one of the other auto-redirecting methods is much better.

The “Javascript” methodJavascript auto-redirects cannot be automatically detected by the search engines because they don’t yet parse Javascript. The script can be placed anywhere on the page, but it is best to place it in the <head> section so that it runs as soon as the page begins to load. This is a typical example:-

<head>
<script language=”javascript”><!–
location.replace(”pagename.html”)
//–>
</script>
…other head section stuff (Title, Description,etc.)…
</head>

“pagename.html” can be any relative or absolute URL, just like a hyperlink URL.

The use of Javascript’s “replace” function causes the new page to replace the current page in the browser’s Back button’s History list. If a visitor then clicks the Back button to go back to where s/he came from, s/he doesn’t go back to the page with the auto-redirect but, instead, goes to the page before that. It avoids the annoying occurence of the Back button taking a person back the auto-redirecting page, which immediately takes him/her forward again.

Using a Index.html page to redirect

Use the following code in your index.html to forward to another page or site.  Locate this file in your domain root.

<head>
<meta http-equiv=”refresh” content=”5;url=http://blog.saltalamacchia.co.uk/index.php”>
</head>

Hiding a redirect to a sub domain
If you put your side within a sub-directory of your domain, you can hide the sub directory displaying in google.  To do this:-Create site in www.mydomain.com/subdirect

  • Create an index.html file in the domain root
  • Within the index file add only
    <?php include(”subdirect/index.html”); ?>
    or in the htaccess file add :
    RewriteEngine on
    RewriteRule ^index\.html$ subdirect/index.html

Note:
When using WordPress in a sub-domain the WordPress .htaccess file is in the subdomain root and the redirect is in the from page root