2015-09-26 45 views
2

我想从我的angularjs应用中移除#,我正在开发一个网站,我想这可能有助于使搜索引擎友好的网站,可能是我错了,请帮助 感谢我如何让我的AngularJS网站在谷歌上爬行?

+0

http://prerender.io或滚动服务器端渲染你自己的。 – YOU

+0

任何免费解决方案? – Punit

+0

它的开源 - https://github.com/prerender/prerender - 你可以在你自己的服务器上运行 – YOU

回答

2

我与乔·劳埃德同意为从您的网址删除#的方式,但它不会帮助你,使你angularjs网站抓取。 看看下面的步骤:

  1. 配置html5mode

    配置(函数($ routeProvider,$ locationProvider){$ locationProvider.html5Mode(真);

  2. 添加<meta name="fragment" content="!">到您的网页,所以谷歌机器人知道要添加?_escaped_fragment_ =在您的请求结束时

  3. 处理?_escaped_fragment_=服务器端并提供所请求的html页面的静态快照(phantomjs可以完成这项工作),以便机器人将索引html页面的渲染版本。

  4. 填写您的sitemap.xml并把它用www.google.com/webmasters/

玩得开心到谷歌!

+0

我使用XAMPP作为本地服务器,我的网站路径是http:// localhost/mysite 第一步之后当我打开http:// localhost/mysite,它将我重定向到http:// localhost 我没有做任何服务器端,我正在使用PHP。 是否有一些.htaccess的东西,我必须做的? 谢谢 – Punit

+0

尝试将添加到您的索引页 –

+0

谢谢,我该如何处理?_escaped_fragment_ = with htaccess – Punit

1

配置

要删除你的url中的#需要添加到你的主模块中。你把应用程序变成html5模式。

//This config is used to remove the # in the html 
app.config(["$locationProvider", function($locationProvider) { 
    $locationProvider.html5Mode({ 
     enabled: true, 
     requireBase: false 
    }); 
}]); 

服务器端(的NodeJS)

这将有一个服务器端的效果,当你打刷新你需要添加额外的路由能够找到新的URL。这将在您的快递js app.js文件中起作用。当公共文件夹包含您的角度应用程序,你有你的index.html文件中有

// ### CATCH REFRESH TO INDEX ### 
app.all('/*', function(req, res, next) { 
    // Just send the index.html for other files to support HTML5Mode 
    res.sendFile('public/index.html', { root: __dirname }); 
}); 
+0

@ christophe.chapron我不确定是否诚实,我的回答只是删除了URL中的哈希,并让nodejs服务器知道如何处理新路径。 –

+0

是的,我同意,但它不会帮助所有的搜索引擎优化:) @Punit:阅读http://www.yearofmoo.com/2012/11/angularjs-and-seo.html +有关ajax网站的谷歌文档 –

+0

我在服务器端使用PHP,你能帮忙吗? OR有没有可能通过HTACCESS文件 – Punit