ajax-seo icon indicating copy to clipboard operation
ajax-seo copied to clipboard

Getting response: <html><head></head><body></body></html>

Open AjeetK opened this issue 8 years ago • 11 comments

Hello, Your solution looks damn good to solve SEO problem. I am trying to implement it to serve the angular app but getting the following response

<html><head></head><body></body></html>

The seo.js file is placed along with the index.html. The following curl command is used to get the html content.

curl localhost:8888/?_escaped_fragment_=/index.html

I have edited the index.html file for the meta tag. Did everything as you explained but not getting the actual response.

AjeetK avatar Jun 04 '16 11:06 AjeetK

I think you are trying to visit:

curl localhost:8888/index.html?_escaped_fragment_=

make sure your angular app can handle url like this:

localhost:8888/index.html#!

see this for the explanations of escaped_fragment: https://developers.google.com/webmasters/ajax-crawling/docs/getting-started#2-set-up-your-server-to-handle-requests-for-urls-that-contain-escaped_fragment

liuwenchao avatar Jun 05 '16 10:06 liuwenchao

@liuwenchao I tried running curl localhost:8888/index.html?_escaped_fragment_= but still its output is blank and the curl gets hanged after running this. How to debug this? I tried replacing the index.html with a plain html content with the required meta tag but still facing the same issue. One more thing I would like to add on about my app configuration is that in the agular app, the HTML5 mode is enabled.

AjeetK avatar Jun 06 '16 11:06 AjeetK

You need to add code in your angular app to be "AJAX crawlable.", which means when your visit urls like localhost:8888/ajax.html#!key=value in the browser or using curl, you will see fully rendered html.

check out the google doc again, you missed the first part of the guide.

I updated readme file of this repo, you inspired me ;)

liuwenchao avatar Jun 11 '16 00:06 liuwenchao

@liuwenchao I understood your point. But as mentioned here one may use either hashbang url way or html5 way to make the website ajax crawlable.

If you wish not to use hashbang URLs but still inform Google that your website contains AJAX content then include this meta tag within the head tag of the file being accessed at the given URL.

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

And as I stated in my previous comment, I am using HTML5 mode, hence it should work.

AjeetK avatar Jun 11 '16 07:06 AjeetK

@liuwenchao The phantomjs server is running fine now and also serving the index page with the following command curl mydomain.com/?_escaped_fragment_=/ But when am trying to access other pages like curl mydomain.com/?_escaped_fragment_=/id/1, it still serves the index page only. Any suggestions for this?

AjeetK avatar Jun 11 '16 09:06 AjeetK

not sure how you fixed the index page.

for the new question: curl mydomain.com/?_escaped_fragment_=/id/1, what's your expectation for the response?

liuwenchao avatar Jun 12 '16 15:06 liuwenchao

@liuwenchao My expectation is to get the page for /id/1 but getting the index page only

AjeetK avatar Jun 12 '16 15:06 AjeetK

meta tag only works for pages without hash fragments, for /id/1 you have to use hashbang mode, and add code in your app to handle hashbang url.

liuwenchao avatar Jun 12 '16 15:06 liuwenchao

@liuwenchao Angular by default supports hashbang urls and I have tested it out too by hitting the url with hashbang. HTML5 mode is also enable in the app and the link I provided above states that either hashbang url or HTML5 mode has to be their to get things work.

AjeetK avatar Jun 12 '16 15:06 AjeetK

I never tried to use both meta tag and hashbang in one ajax page, meta tag may override hashbang. You can try to remove the meta tag to see if hashbang is taking control of it.

liuwenchao avatar Jun 12 '16 15:06 liuwenchao

By the way, I shifted to prerender only as this solution was not working out for me. Most probably am doing something wrong while setting up your solution. May be you should put some more things in the documentation (detailed documentation) like prerender guys have done. What I think is, the documentation should be like there should not be any assumption at the users end. Everything should be mentioned in a detailed way (without assuming anything for a novice user). Thanx a lot for your help :)

AjeetK avatar Jun 12 '16 15:06 AjeetK