Laravel和AngularJS的SEO优化,不使用hashbang URL

3

我使用Laravel作为后端,使用AngularJS开发了一个网站。

我启用了AngularJS中的html5mode,以便URL不具有哈希标记。

使用grunt工具,我在snapshots文件夹中创建了快照。有5个页面,每个页面都输出为snapshot__page.html到snapshots文件夹中。

我在Laravel路由文件中使用以下代码来重定向所有请求到index文件,以便Angular可以处理其余部分。

App::missing(function($exception)
{
    return View::make('index');
});

这个网站可以通过浏览器访问:

http://www.domain.com/ 
http://www.domain.com/page1
http://www.domain.com/page2 

etc和快照在哪里

http://www.domain.com/snapshots/snapshot__.html
http://www.domain.com/snapshots/snapshot__page1.html
http://www.domain.com/snapshots/snapshot__page2.html

谷歌建议包括:
<meta name="fragment" content="!">

以便爬虫按照以下方式访问页面。
http://www.domain.com?_escaped_fragment=
http://www.domain.com/page1?_escaped_fragment=
http://www.domain.com/page2?_escaped_fragment=

我们可以为这样的请求提供快照服务。

我的问题出在 .htaccess 文件上。

即使我使用 "?escaped_fragment=" 访问测试页面,索引页面也会被加载。这是 Laravel 捕获了 404 路由并提供了索引页面。 有很多关于如何为 URL 中间出现的 ?escaped_fragment= 提供快照的文档。 类似的问题在这里讨论过

https://groups.google.com/forum/#!msg/angular/lK8M5bFwbkQ/FN1t1SYD3QkJ .htaccess for SEO bots crawling single page applications without hashbangs

但是所提供的 .htaccess 看起来不起作用。

我的 .htaccess 文件如下。我正在尝试修改 .htaccess。

<IfModule mod_rewrite.c>

 ############################################
 ## enable rewrites

Options +FollowSymLinks
RewriteEngine on

#Access site only with www
RewriteCond %{HTTP_HOST}       !domain\.com$
RewriteRule [domain]?(.*) http://www.domain.com/$1 [R=301,L]

#Snapshots for SEO  
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$
RewriteRule ^(.*)$ /snapshots/snapshot__$1.html [L,NC]


#Laravel Stuff
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]


</IfModule>
1个回答

0
根据您上面的规范,这行代码末尾有一个下划线。
重写条件 %{QUERY_STRING} ^_escaped_fragment_=$。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接