我在html5模式下使用angular
$routeProvider.otherwise({redirectTo : '/index' });
$locationProvider.html5Mode(true).hashPrefix('!');
为此我有 htaccess 来处理谷歌索引
# 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_=
快照存在,我尝试在那里硬编码 index-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/$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/$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]
关于AngularJS SEO htaccess : redirect root domain to snapshot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28113109/