Actually The above code is working.Google started crawling after 4 days(long time)..Thought there was mistake in the code.
Hope this will be helpful to other developers.
题
I am trying to make an angularjs site crawl-able.To do that i am using ?_escaped_fragment= solution as suggested by Google.
For example:
When google sees request with hash fragment like "http://xample.com/#!/Home"
,it convert the url into "http://xample.com/?_escaped_fragement_=/Home"
.
I have implemented Index controller
in rails that accepts such request and redirect that request to crawler controller
which in turn provide dynamically generated HTML snapshot to the Google.
However except my home page http://xample.com/
no other pages are getting crawled.(maybe because of hashbang)
Below are the url that are not crawled even after implementing ?_escaped_fragment_= solution as suggested by google:-
http://xample.com/#!/Home
http://xample.com/#!/xyz
http://xample.com/#!/abc
http://xample.com/#!/def
Controllers Used by me:-
Index controller
accepts Url with "?_escaped_fragment_="
class IndexController < ApplicationController
def index()
if params['_escaped_fragment_'] == '/Home'
redirect_to :controller=>'crawler', :action => 'crawlhome'
return
elsif params['_escaped_fragment_'] == '/Xyz'
redirect_to :controller=>'crawler', :action => 'crawlxyz'
return
end
elsif params['_escaped_fragment_'] == '/abc'
redirect_to :controller=>'crawler', :action => 'crawlabc'
return
end
end
elsif params['_escaped_fragment_'] == '/def'
redirect_to :controller=>'crawler', :action => 'crawldef'
return
end
end
Crawler controller
class CrawlerController < ApplicationController
layout false
require 'net/http'
require 'uri'
def crawlhome
@data = "getting data from api and displaying same data in view"
end
def crawlXyz
@data = "getting data from api and displaying same data in view"
end
def crawlabc
@data = "getting data from api and displaying same data in view"
end
def crawldef
@data = "getting data from api and displaying same data in view"
end
end
The Seo concerned person working in my company suggested to me to implement the website without hashbang
(push state) in the url.Is this the right solution for the problem.
This however does not work in the non-Html browsers.
What might be the problem with implementing http://xample.com/#!/Home
.Why is it not crawling in the above case.
I have tried many different solutions from the forum but still not giving me the proper results.
解决方案
Actually The above code is working.Google started crawling after 4 days(long time)..Thought there was mistake in the code.
Hope this will be helpful to other developers.