Forum Moderators: phranque
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]
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]
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.
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
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.
* 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