Php displays different content to visitors and crawlers
Source: Internet
Author: User
To improve the user experience of web pages, we often do some unfriendly things about search engines, but in some cases this is not irrecoverable, you can provide a good user experience and SEO by displaying different content to natural persons and search engine robots. I have heard that this method violates some search engine operating principles and may be penalized by various search engines or even deleted from websites. so I have just removed this process until I confirm that it is not cheating. if you have the courage to continue using the service, you are at your own risk.
The homepage and archive page of this blog displays articles in the form of a list. only the content of the article is loaded when a visitor clicks to expand the article. because the content of the article contains a lot of text and images, it requires a lot of loading time and traffic. displaying webpages to visitors as soon as possible can retain a large number of visitors. for mobile phone users, loading time and traffic are more important.
In general, the homepage of a website is the most visited page by the search engine. you should try to show meaningful content to it, but to display the article in the form of a list, visitors and search engines can only obtain the title information of an article. the content or abstract of the article (especially the first sentence) is extremely important for SEO, so we should try to send the content to crawlers.
Well, we can use the User Agent to determine whether the visitor is a crawler. If yes, the document will be displayed in the general form; otherwise, the document list will be displayed in the form of a list. you can use the following PHP method to determine whether a crawler is used:
The code is as follows:
Function is_crawler (){
$ UserAgent = strtolower ($ _ SERVER ['http _ USER_AGENT ']);
$ Spiders = array (
'Googlebot ', // Google crawler
'Baidider Ider ', // Baidu crawler
'Yahoo! Slurp ', // Yahoo crawler
'Yodaobot ', // Youdao crawler
'Msnbot '// Bing crawler
// More crawler keywords
);
Foreach ($ spiders as $ spider ){
$ Spider = strtolower ($ spider );
If (strpos ($ userAgent, $ spider )! = False ){
Return true;
}
}
Return false;
}
This is my method. crawlers sort access comments from high to low, and then use the following method to display different content to crawlers and natural persons.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service