Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointing crawler to HTML snapshot

Tags:

html

ajax

php

I'm trying to make my AJAX website crawlable:

Here is the website in question.

  • I've created a htmlsnapshot.php that generates the page (this file needs to be passed the hash fragment to be able to generate the right content).
  • I don't know how to get the crawler to load this file while getting normal users to load the normal file.
  • I don't really understand what the crawler does to the hash fragment (and this probably is part of my problem.)

Does anybody have any tips?


1 Answers

The crawler will divert itself. You just need to configure your PHP script to handle the GET parameters that Google will be sending your site (instead of relying on the AJAX).

Basically, when Google finds a link to yourdomain.com/#!something instead of requesting / and running the JavaScript to make an AJAX request for data something, Google will automatically (WITHOUT you doing anything) translate anything that comes after #! in your URL to ?_escaped_fragment_=something.

You just need to (in your PHP script) check if $_GET['_escaped_fragment_'] is set, and if so, display the content for that value of something.

It's actually very easy.

like image 199
Mahmoud Al-Qudsi Avatar answered Dec 08 '25 08:12

Mahmoud Al-Qudsi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!