A JavaScript redirect is a piece of JavaScript code that is used to automatically transfer a visitor from a landing page to a different target page. Although there may be legitimate reasons to transfer visitors and users to a different URL, generally a JavaScript redirect is employed as a sneaky method to trick search engines and direct user traffic to a website completely unrelated to a search.

JavaScript redirects and cloaking considered “black hat”


A JavaScript redirect falls under the category of “cloaking,” which is a practice of serving different results to users through search engine results. Besides redirection, another example of cloaking could be providing a web page with HTML text to a search engine, while giving a page full of images or Flash content to a user’s browser.

Web page elements like JavaScript, Flash, or other rich media files generally cannot be crawled effectively by search engines. Thus, when a page containing JavaScript is indexed by a search engine, any links hidden by JavaScript coding may not be followed by the search engine. Because of this fact, many SEO firms and underhanded webmasters may employ these “sneaky” methods to fill a web page with common search terms in order to fool a search engine and redirect the visitor to an unrelated website.

Cloaking is frowned upon by search engines. In fact, any practice of purposely deceiving a search engine in order to serve different results to a user is cause for removal from a search engine’s index. Thus, SEO companies that use software programs that auto-generate doorway web pages with search keywords for the simple purpose of redirecting a visitor with sneaky JavaScript will eventually be discovered and flagged for removal.

Yet another reason to avoid JavaScript redirection is that many users turn off the JavaScript function on their browsers. Whether your intention to redirect is legitimate or sneaky, a non-java functioning browser will simply display whatever text is on the web page, as well as the JavaScript code, and not perform the redirect.

Applicable Reasons to Redirect

There are cases, however, where there are legitimate reasons for wanting to redirect a user to a different web page:

  • URL misspelling – Some users may commonly misspell a URL. Many big websites may purchase extra domains with these common misspellings and use them as a simple landing page to redirect to the actual domain. An example may be when a user types “gooogle.com” or even “googel.com” in a URL window. Despite the misspelling, users are automatically redirected to the actual “google.com” domain.
  • New domain – Sometimes it is necessary for a business or website to change its name. When that results in a new domain name, it is acceptable to continue using the old domain as a redirect page to the new domain. For instance, when two businesses merge, it is likely they will use only one main domain as a consolidated website and use the other as a redirect page.
  • Forwarding a .net to .com – Oftentimes a domain is purchased by a business as a .net or .biz when the more common .com is unavailable. If at some point the .com domain becomes available or is purchased by the business, they could continue using a .net as a redirect to the new domain.

What You Should Do

If you need to employ a redirect on a particular web page, remember that sneaky methods are not recommended. Even though JavaScript is an acceptable method to redirect users, search engines are becoming savvier, looking for hidden text and sneaky redirects. Google posts this basic principle on their webmaster guidelines:

Make pages primarily for users, not for search engines. Don't deceive your users or present different content to search engines than you display to users, which is commonly referred to as "cloaking."

The best way to create a redirect without looking potentially sneaky is to use a .htaccess file, such as a 301 Permanent Redirect or 302 Temporary Redirect. These codes are the most efficient and search engine friendly methods, and they will preserve your web page ranking as well. Simply create one of the following codes in a text editor and save it as a .htaccess file:

redirect 301 /filename.ext http://www.domain.tld/newfilename.ext # permanent redirect

redirect 302 /filename.ext http://www.domain.tld/newfilename.ext # temp redirect

These codes create no delay in a redirect since a server checks first for a .htaccess file. If it finds one, a browser is sent directly to the new site without loading the old page. 

Redirecting user traffic from one website to another is a common practice. If the purpose of redirect is simple and legitimate, there is no reason to use JavaScript coding. An .htaccess file works perfectly fine. Remember that cloaking and using doorway redirect web pages are considered deceptive, so only employ a redirect when absolutely necessary.

Resources:

http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=66355

http://www.google.com/support/webmasters/bin/answer.py?answer=35769

http://www.mattcutts.com/blog/seo-mistakes-sneaky-javascript/

http://www.webweaver.nu/html-tips/web-redirection.shtml