3

I'm using Google App Engine to host an AngularJS app with a Python webservice. The root path / is setup to return index.html, /api/* requests go to the Python controllers for webservice calls, and any other path goes to static resources (images, views, etc.)

I'm trying to use the hashbang/_escaped_fragment_ technique to get the app setup for search engine indexing. As I understand it, a url of http://www.whatever.com/#!/news will be transformed by a search engine to http://www.whatever.com/?_escaped_fragment_=/news

It's not a problem to write some code to handle that request, but it is a problem to have that code listen on the root path, since that's mapped to index.html

Is there a metatag or something to tell search engines to use a different path (not /) when issuing the _escaped_fragment_ request?

If not, is there a way in Google App Engine to have requests to / serve up index.html, but if the _escaped_fragment_ query parameter is there, then go to a controller to handle the request?

At the moment the only thing I've found to work is to have a controller for the root path, where it checks for the _escaped_fragment_ parameter. If there, it renders content for a search engine, if not, it reads the index.html and writes it to the response. I'm hoping there's a better option available.

user605331
  • 3,718
  • 4
  • 33
  • 60

1 Answers1

1

You can simply add the following to your page and then handle the www.example.com?_escaped_fragment_=:

<meta name="fragment" content="!">

From Google Developers for Making AJAX Applications Crawlable Getting Started tutorial:

In other words, if you place <meta name="fragment" content="!"> into the page www.example.com, the crawler will temporarily map this URL to www.example.com?_escaped_fragment_= and will request this from your server. Your server should then return the HTML snapshot corresponding to www.example.com.


Also from the Full Specification page and more specifically from the section for Pages without hash fragments:

The following important restrictions apply:

  1. The meta tag may only appear in pages without hash fragments.
  2. Only "!" may appear in the content field.
  3. The meta tag must appear in the head of the document.
Lipis
  • 21,388
  • 20
  • 94
  • 121
  • Perhaps I'm misunderstanding your answer, but this sounds like what I'm already doing. I am trying to get the crawler to make it's request to www.example.com/crawler-prefix/?_escaped_fragment_=/original/path The "crawler-prefix" is the main thing I am trying to get working here. If that cannot be done, then I was looking for a way in App Engine to have the / path mapped to a static file, unless the query param is there, in which case I want it to go to a controller. – user605331 Jan 29 '14 at 19:39
  • @user605331 I think I understood you now.. you will have to handle that within the app instead of mapping it only in the `app.yaml` and if there is no `_escaped_fragment_` param for the `/` request, render the AngularJS enabled `index.html` otherwise render something for the crawlers.. – Lipis Jan 29 '14 at 19:54
  • OK, then that is what I am doing now. It's unfortunate that there is not a nicer way to handle the case. – user605331 Jan 29 '14 at 20:26
  • @user605331 well for the other requests you will have to do it anyway.. so why not handling it for the root path as well? It's not totally static site because otherwise how will you generate the pages that are needed for the crawlers?! – Lipis Jan 29 '14 at 20:43