3
votes

I have developed a website with Laravel backend and AngularJS for the client side. I have enabled html5mode in AngularJS so that the URLs do not have hashbangs.

Using grunt I have created snapshots inside snapshots folder. There are 5 pages and each page is output as snapshot__page.html to snapshots folder.

I use following code in Larvel routes file to redirect all requests to index file, so that Angular can take care of the rest.

App::missing(function($exception)
{
    return View::make('index');
});

The website can be accessed from browser with

http://www.domain.com/ 
http://www.domain.com/page1
http://www.domain.com/page2 

etc and snapshots are in

http://www.domain.com/snapshots/snapshot__.html
http://www.domain.com/snapshots/snapshot__page1.html
http://www.domain.com/snapshots/snapshot__page2.html

Google states to include

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

so that the crawler will access pages as follows.

http://www.domain.com?_escaped_fragment=
http://www.domain.com/page1?_escaped_fragment=
http://www.domain.com/page2?_escaped_fragment=

and we can serve snapshots to such a request.

The problem with me lies in the .htaccess file.

Even though when I access with "?escaped_fragement=" to test the pages, the index page gets loaded. This is Laravel catching the 404 routes and serving the index page. There is lot of documentation on how to serve snapshots for ?escaped_fragment= appearing in between the URL. A similar problem is discussed here

https://groups.google.com/forum/#!msg/angular/lK8M5bFwbkQ/FN1t1SYD3QkJ .htaccess for SEO bots crawling single page applications without hashbangs

but the .htaccess provided doesn't seem to work.

My .htaccess file is as follows. I was fiddling with .htaccess.

<IfModule mod_rewrite.c>

 ############################################
 ## enable rewrites

Options +FollowSymLinks
RewriteEngine on

#Access site only with www
RewriteCond %{HTTP_HOST}       !domain\.com$
RewriteRule [domain]?(.*) http://www.domain.com/$1 [R=301,L]

#Snapshots for SEO  
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$
RewriteRule ^(.*)$ /snapshots/snapshot__$1.html [L,NC]


#Laravel Stuff
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]


</IfModule>
1

1 Answers

0
votes

based on your spec above, this line has a trailing underscore

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$