What is the recommended way to redirect a site to a different site?
As I understand this can be done by either changing the CNAME开发者_运维问答
record in the DNS. Or this can be done using HTTP redirects. I am wondering what is a recommended way of doing this and pros and cons of each approach. What would be friendlier option for search engine like Google?
The correct method usually stated for URL redirection is to have the server configured to send the 301
Moved Permanently or 307
Moved Temporarily HTTP Header Code.
The Javascript window.location.href
method will probably be ignored by search engines, while the <meta>
refresh method is usually considered a bad practice.
The Wikipedia page documents each method with a fair amount of detail.
Extending Yi Jiang's fine answer, there is also 303 See Other
which is subtly different from 301 and 307.
- 301 roughly says "do not try this URI again, always use the one I'm giving you now".
- 303 roughly says "you may try this URI again, but use the one I'm giving you for now with GET".
- 307 roughly says "you may try this URI again, but use the one I'm giving you for now with the same method".
The important thing about 303 is that if the original request was not a GET it is implied that the operation succeeded but further response is to be found elsewhere. Semantically the difference between 301/307 and 303 is that the former are replacements (this replaces that) and the latter is a diversion (this is in addition to that).
You would want to use the .htaccess file to ask the HTTP server to send a 301 response.
Reference
精彩评论