Laravel and AngularJS SEO without hashbang url
I have developed a website with Laravel and AngularJS support for the client side. I have included html5mode in AngularJS so that urls don't have hashbangs.
Using grunt I have created snapshots inside the snapshot folder. There are 5 pages and each page is output as snapshot__page.html to the snapshot folder.
I am using the following code in the Larvel routes file to redirect all requests to the index file so that Angular can take care of the rest.
App::missing(function($exception)
{
return View::make('index');
});
The website can be accessed in a browser using
http://www.domain.com/
http://www.domain.com/page1
http://www.domain.com/page2
etc. and the 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 announces inclusion
<meta name="fragment" content="!">
so that the crawler can access the following pages.
http://www.domain.com?_escaped_fragment=
http://www.domain.com/page1?_escaped_fragment=
http://www.domain.com/page2?_escaped_fragment=
and we can use snapshots for such a request.
The problem with me is the .htaccess file.
Even though when you access "? Escaped_fragement =" to check pages, the index page is loaded. It's Laravel catching 404 routes and serving the index page. There is a lot of documentation on how to take snapshots: escaped_fragment = appears between the url. A similar issue is discussed here.
https://groups.google.com/forum/#!msg/angular/lK8M5bFwbkQ/FN1t1SYD3QkJ .htaccess for SEO bots crawling single page apps without hashbangs
but the .htaccess provided doesn't work.
My .htaccess file looks like this. I was messing around 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>
source to share