Forum Moderators: Robert Charlton & goodroi

Message Too Old, No Replies

Using JavaScript 301 redirection from non-www to www.

Will search engines recognize such redirection?

         

Blade3

10:28 am on Mar 2, 2006 (gmt 0)

10+ Year Member



Hi,

Is it ok to use javascript for redirecting all non-www pages to www? The purpose of redirection is to avoid content duplication. I do not have permission for 301 redirection.

The JavaScript runs as:

response.setStatus(301);
response.setHeader( "Location", "http://www.domain.com/" );
response.setHeader( "Connection", "close" );

Will search engines recognize this redirection without any penalties? Please input your valuable comments. Thank You.

- Blade3

tedster

8:21 am on Mar 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a java servlet, and it runs on the server. It's not javascript, which is a client-side technology.

I am not all that knowledgable in jsp, so I hesitate to say yes or no on whether this code is rock solid. Why don't you set up a test and see how it works. After it's in place on the server, then type a "no-www" url into the browser and:

1. Verify that a 301 http header is actually returned (you can use FireFox with the LiveHeaders extension, or use the server header checker on our sister site SearchEngineWorld -- [searchengineworld.com...]

2. Then verify that the browser is redirected to the exact same url, except that the "www" is in place.

Blade3

4:54 am on Mar 4, 2006 (gmt 0)

10+ Year Member



Tedster

You made me clear that it is a java servlet that runs on the server and javascript runs at client-side.

I tested a page by placing this code in head section and placed on the server. When I typed "no-www" url into the browser, it redirected the page to the root with www.

I also verified this at your sister site, the following information was displayed:

Server Response: [domain.com...]
Status: HTTP/1.1 301 Moved Permanently
Date: Sat, 04 Mar 2006 05:21:05 GMT
Server: Apache/2.0.40 (Red Hat Linux)
Connection: close
Set-Cookie: JSESSIONID=6954B95162B6B9A8F8A87A136860C3BD.tomcat; Path=/
Location: [domain.com...]
Transfer-Encoding: chunked
Content-Type: text/html;charset=ISO-8859-1

Can search engines accept this type of redirection?

Many thanks Tedster.