我觉得我已尝试过每一个选项,没有任何成功.首先让我列出我尝试过的选项:
使用prerender与Apache:
我已尝试使用以下步骤:
在角度:
$locationProvider.html5Mode(true);
<head> <Meta name="fragment" content="!"> </head>
配置Apache:
RewriteEngine On # If requested resource exists as a file or directory # (REQUEST_FILENAME is only relative in virtualhost context,so not usable) RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d # Go to it as is RewriteRule ^ - [L] # If non existent # If path ends with / and is not just a single /,redirect to without the trailing / RewriteCond %{REQUEST_URI} ^.*/$ RewriteCond %{REQUEST_URI} !^/$ RewriteRule ^(.*)/$$1 [R,QSA,L] # Handle Prerender.io RequestHeader set X-Prerender-Token "YOUR_TOKEN" RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR] RewriteCond %{QUERY_STRING} _escaped_fragment_ # Proxy the request RewriteRule ^(.*)$http://service.prerender.io/http://%{HTTP_HOST}$1 [P,L] # If non existent # Accept everything on index.html RewriteRule ^ /index.html
这完全没有办法:Google无法读取我的子页面.
使用Node / Phantomjs来渲染页面
var express = require('express'); var app = module.exports = express(); var phantom = require('node-phantom'); app.use('/',function (req,res) { if (typeof(req.query._escaped_fragment_) !== "undefined") { phantom.create(function (err,ph) { return ph.createPage(function (err,page) { return page.open("https://system.dk/#!" + req.query._esca$ return page.evaluate((function () { return document.getElementsByTagName('html')[0].innerHT$ }),function (err,result) { res.send(result); return ph.exit(); }); }); }); }); } else res.render('index'); }); app.listen(3500); console.log('Magic happens on port ' + 3500);
在这里,我创建了这个站点,然后在我的Apache配置中添加了一个代理,以便所有请求都指向我的域端口3500.
这没有工作,因为它不能渲染索引,当我终于得到它发送JavaScript不会呈现的HTML页面.
以下自定义快照指南
然后我遵循这个指南:
http://www.yearofmoo.com/2012/11/angularjs-and-seo.html
然而,这需要我自己制作一些不是我正在寻找的东西,并且烦人的维护.加上make-snapshot在我的服务器上不起作用.
理论上你不必先将你的页面推送到谷歌搜寻器.他们现在解析javascript.
http://googlewebmastercentral.blogspot.ca/2014/05/understanding-web-pages-better.html
原文链接:https://www.f2er.com/angularjs/140626.htmlGoogle解析我的angularJS网站很好. https://www.google.nl/search?q=site%3Atest.coachgezocht.nu
使用$locationProvider.html5Mode(true);和:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !index RewriteRule (.*) index.html [L]