Angular SEO / NodeJS / PhantomJS - Serve static html files
I am implementing my own PhantomJS solution to provide snapshots to crawlers.
- My snapshots are located here: / public / snapshots
- My url looks like this: http://example.com/#!/a/b/c
When the crawler comes in, url / #! / Is transformed like this: http://example.com/?_escaped_fragment_=/a/b/c
I want to use static files from / public / snapshots for the crawler when it crawls one of my pages.
Current solution
I intercept URLs and rewrite this:
- http://example.com/?_escaped_fragment=/a/b/c (with nginx)
- into this: http://example.com/snapshots/a/b/c
It comes to a route in my NodeJS where I get the name of the html file according to the url parameters. In this case, it would be /snapshots/a/b/c.html
I get the file with:
fs.readFile(file_path, function(err, content)
{
res.set('Content-Type', 'text/html');
res.send(content);
});
Problem
When I set Content-Type to HTML Angular / Express does a redirect and my url gets this:
If I go to this URL, I can see the correct snapshot file /a/b/c.html, but after a few milliseconds, I am redirected to my home page.
Questions
- How can I serve static files without redirecting Express and Angular?
- If I do a redirect from http://example.com/?_escaped_fragment_=/a/b/c to http://example.com/snapshots/a/b/c.html that works well, would search engines agree with this?
thank
source to share
No one has answered this question yet
Check out similar questions: