Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crawlable AJAX with _escaped_fragment_ in htaccess

Hello fellow developers!

We are almost finished with developing first phase of our ajax web app. In our app we are using hash fragments like:

http://ourdomain.com/#!list=last_ads&order=date

I understand google will fetch this url and make a request to the server in this form:

http://ourdomain.com/?_escaped_fragment_=list=last_ads?order=date&direction=desc

everything is perfect, except...

I would like to route this kind of request to another script

like so:

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
RewriteRule ^$ /webroot/crawler.php$1 [L]

The problem is, that when I try to print_r($_REQUEST) in crawler.php I get only:

Array
(
    [_escaped_fragment_] => list=last_ads?order=date
    [direction] => desc
)

what I'd like to get is

Array
(
    [list] => last_ads
    [order] => date
    [directions] => des
)

I know I could use php to further break the first argument, but I don't want to ;)

please advise

==================================================== EDIT... some corrections in text and logic

like image 693
DS_web_developer Avatar asked Nov 09 '11 10:11

DS_web_developer


3 Answers

Your forgot QSA directive (everyone missed the point =D )

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
RewriteRule ^$ /webroot/crawler.php%1 [QSA,L]

By the way your $1 is well err... useless because it refers to nothing. So this should be:

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
RewriteRule ^$ /webroot/crawler.php [QSA,L]

Tell me if this works.

like image 76
Olivier Pons Avatar answered Oct 22 '22 14:10

Olivier Pons


If I'm not mistaken.

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
RewriteRule ^$ /webroot/crawler.php?%1 [L]
like image 30
Gerben Avatar answered Oct 22 '22 13:10

Gerben


Maybe is obvious for you, but in the documentation talk about escaped characters: Set up your server to handle requests for URLs that contain

The crawler escapes certain characters in the fragment during the transformation. To retrieve the original fragment, make sure to unescape all %XX characters in the fragment. More specifically, %26 should become &, %20 should become a space, %23 should become #, and %25 should become %, and so on.

like image 1
lluisi Avatar answered Oct 22 '22 12:10

lluisi