AngularJS SEO htaccess:将根域重定向到快照

AngularJS SEO htaccess: redirect root domain to snapshot

我使用 angular 和 html5 模式

 $routeProvider.otherwise({redirectTo : '/index' });
 $locationProvider.html5Mode(true).hashPrefix('!');

为此我有 htaccess 来处理 google 索引

 # Rewrite anything with google appended string to english version of the snapshot
 RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
 RewriteCond %{HTTP_HOST}  ^touchtyping.guru [NC]
 RewriteRule ^ snapshots%{REQUEST_URI}-en.html [L]

 # Rewrite everything else to index.html to allow html5 state links
 RewriteRule ^ index.html [QSA,L]

这会重定向到所有子页面的适当快照,例如:

 http://touchtyping.guru/learn-touch-typing?_escaped_fragment_=
 http://touchtyping.guru/index?_escaped_fragment_=

但它不适用于如下所示的根域,呈现 /index 页面,而不是重定向到它的快照:

 http://touchtyping.guru/?_escaped_fragment_=

快照存在,我尝试在那里硬编码索引-en.html,但没有成功。似乎 htaccess 在这种情况下没有捕获查询字符串,正在加载 angular 路由。我该如何解决?

更新------------------------------------

整个 htaccess 文件:

 RewriteEngine on

 # Don't rewrite files or directories
 RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^ - [L]

 # Redirect http://www. to just http://
 RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
 RewriteRule ^(.*)$ http://%1/ [R=301,L]

 RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
 RewriteCond %{HTTP_HOST}  ^touchtyping.guru [NC]
 RewriteRule ^ snapshots%{REQUEST_URI}-en.html [L]

 RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
 RewriteCond %{HTTP_HOST}  ^(es|pl|en).touchtyping.guru [NC]
 RewriteRule ^ snapshots%{REQUEST_URI}-%1.html [L]

 # Rewrite everything else to index.html to allow html5 state links
 RewriteRule ^ index.html [QSA,L]

您是否尝试过为此添加特定规则?

 RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
 RewriteCond %{HTTP_HOST}  ^touchtyping.guru [NC]
 RewriteRule ^$ snapshots/index-en.html [L]

编辑:

尝试稍微重新安排您的规则:

 RewriteEngine on

 # Redirect http://www. to just http://
 RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
 RewriteRule ^(.*)$ http://%1/ [R=301,L]

 RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
 RewriteCond %{HTTP_HOST}  ^touchtyping.guru [NC]
 RewriteRule ^(index\.html)?$ snapshots/index-en.html [L]

 RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
 RewriteCond %{HTTP_HOST}  ^(es|pl|en).touchtyping.guru [NC]
 RewriteRule ^(index\.html)?$ snapshots/index-%1.html [L]

 # Don't rewrite files or directories
 RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^ - [L]

 RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
 RewriteCond %{HTTP_HOST}  ^touchtyping.guru [NC]
 RewriteRule ^ snapshots%{REQUEST_URI}-en.html [L]

 RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
 RewriteCond %{HTTP_HOST}  ^(es|pl|en).touchtyping.guru [NC]
 RewriteRule ^ snapshots%{REQUEST_URI}-%1.html [L]

 # Rewrite everything else to index.html to allow html5 state links
 RewriteRule ^ index.html [QSA,L]