Forum Moderators: phranque

Message Too Old, No Replies

Getting a 302 server response with non www site

         

snooprock

10:47 am on Jul 7, 2006 (gmt 0)

10+ Year Member



Hello everyone. This is my first post and I am technically challenged so bare with me. I have recently put the following code in my htaccess file to redirect the non www version of my site to the www version. When doing a server header check I am getting a 302 response. Shouldn't I be getting a 301 or 200, I guess what I am asking is if this 302 response is normal or if it is detrimental to my rankings.

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

I appreciate any insight. I have tried to figure this out on my own to no avail.

[edited by: jdMorgan at 2:12 pm (utc) on July 7, 2006]
[edit reason] Example,com [/edit]

trillianjedi

11:49 am on Jul 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's mine which seems to work just fine:-

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

You need to specify the "301".

TJ

PS : Welcome to WebmasterWorld!

[edited by: jdMorgan at 2:13 pm (utc) on July 7, 2006]
[edit reason] Example.com, formatting [/edit]

snooprock

2:24 pm on Jul 7, 2006 (gmt 0)

10+ Year Member



Thanks TR, I noticed you don't have a $ symbol in front of your http and mine does not. I trust yours is the right way to do it. I figure anyone with 5K plus posts most know what they are talking about lol.

The other thing I need to learn is what server response error codes I should be looking for that may be detrimental to anything regarding my site. I have noticed quite a few 403 codes. I don't quite know what they all mean even though I have a list. I am just trying to get to the point where I know which codes are bad that may be affecting me so I can learn more about those codes and how to rectify them. Thanks for the clarification.

trillianjedi

2:27 pm on Jul 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I figure anyone with 5K plus posts most know what they are talking about lol.

Hehe - not true. I'm not an Apache expert by any means, I simply copied/pasted the code that I know works for me from my .htaccess file.

However, I can tell you that code was actually written by the Moderator of this forum who has over 10k posts to his name ;)

Give it a try and see what happens. I know these redirects are not always straightforward.

TJ

snooprock

2:39 pm on Jul 7, 2006 (gmt 0)

10+ Year Member



Right on brother. It redirects correctly and is also giving me the 301 response during a header checker as oppossed to the 302 before. Thanks a bunch.

jdMorgan

2:53 pm on Jul 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A review of the Status codes [w3.org] section of RFC-2616 - Hypertext Transfer Protocol -- HTTP/1.1 will answer part of the question.

403 is "Access Forbidden." 302 is "Found" or "Moved Temporarily." The latter can be detrimental if the resource has not in fact been moved temporarily, but rather permanently.

In short, the server response code must be 100% correct/accurate/true for best results. Generally, browsers don't really care, but if you tell a search engine that something has moved temporarily, then it will take you at your word and expect that condition to be temporary. Therefore, it will keep the original URL and continue to request it. If on the other hand, you generate a 301 response, then a search engine will (eventually) replace the old URL with the new one speicified in the 301 response.

Many, many of the problems that people have with search engines have to do with returning incorrect or inappropriate server responses, either through ignorance, because their (generally 'cheap') hosting does not allow them proper control of the server, or because they're trying to be 'tricky.' Combined with the search engines' attempts at 'articifical intelligence' intended to compensate for webmasters' ignorance or lack of server control, some situations can be disastrous. It is best to follow the protocol exactly to avoid trouble.

  • 301 means a resource has moved permanently, and it *will not* move back in the forseeable future.
  • 302 effectively* means a resource has moved temporarily, but *will* return to the requested URL in the foreseeable future.
  • 404 means a resource cannot be found, and indicates sloppy webmastering. It is impossible for the client to determine whether a 404 condition is permanent or temporary, as it may be the result of the webmaster removing a file, a bad link, or a malfunctioning cgi script.
  • 410 means a resource is gone, it was intentionally removed, and it won't be back. It is nicely unambiguous.

    * 302 is especially ambiguous because it was ill-defined in HTTP/1.0. HTTP/1.1 attempts to rectify that shortcoming by providing the explicit 307-Moved Temporarily response, but support for that server response code remains spotty.

    It's important to realize that these codes are not 'detrimental' in and of themselves, but rather because of the action that search engines may take in response to them. There are so many broken Web sites on-line that search engines are now trying to 'figure out' what the actual situation is, rather than trusting the server to always respond correctly. But when they do this, they can only cover the most common cases of erroneous response. Throw one more tiny complication into the mix, and their attempt to 'be nice' to badly-configured sites can go very wrong.

    If you treat HTTP/1.1 as 'The Law,' and check your server responses thoroughly using a server headers checker, you will have few problems.

    [added] Questions about 'hats and dollars' can be answered by reviewing the short Regular Expressions tutorial cited in our Forum Charter (link at upper left of this page). [/added]

    Jim

  • snooprock

    3:29 pm on Jul 7, 2006 (gmt 0)

    10+ Year Member



    It is all starting to sink in finally and I really feel like I am making progress through this maze. Thanks for your time and detailed response JD, it is most appreciated.