Optimizing AngularJS driven website for search engines
19 Jun 2013
So here’s what I did. Consider it a poor man’s SEO fix. First I added this meta tag to tell the search engines that this site is AJAX driven:
That will basically make the search engine try an alternate route for your content. So for example, instead of going to http://www.mysite.com/about, it will go to http://www.mysite.com/?_escaped_fragment_=about
So the next thing we’ll need to do is modify .htaccess to handle those URLs with _escaped_fragment_ in them:
So as you’ll notice, I’m sending all of those requests to a special PHP script (crawler.php) just created for the crawlers/bots:
Basically what that script is doing is reading the meta tags off of a JSON file based on which URL is being requested. Here’s an example:
Now as a bonus, you could program AngularJS to read meta tags for each page from this JSON file as well. Just so you have all the meta information in one central place.