AngularJS SEO htaccess的:重定向根域为快照 [英] AngularJS SEO htaccess: redirect root domain to snapshot

查看:179
本文介绍了AngularJS SEO htaccess的:重定向根域为快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用角与HTML5模式

  $ routeProvider.otherwise({redirectTo:/指数'});
 $ locationProvider.html5Mode(真).hash preFIX(!);
 

和我有htaccess的处理谷歌索引

 #重写与谷歌附加字符串到快照的英文版什么
 的RewriteCond%{QUERY_STRING} ^ _escaped_fragment_ =
 的RewriteCond%{HTTP_HOST} ^ touchtyping.guru [NC]
 重写规则^快照%{REQUEST_URI} -en.html [L]

 #改写一切以index.html来让HTML5状态的链接
 重写规则^的index.html [QSA,L]
 

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

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

但它并不像下面的根域,渲染,而不是重定向到它/索引页,作品的快照:

  http://touchtyping.guru/?_escaped_fragment_=
 

快照存在,我尽力codeD指数en.html那里,但没有成功。好像htaccess的不赶查询字符串在这种情​​况下,加载角路由。我该如何解决呢?

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

全htaccess文件:

  RewriteEngine叙述上

 #不要重写文件或目录
 的RewriteCond%{} REQUEST_FILENAME -f [OR]
 的RewriteCond%{} REQUEST_FILENAME -d
 重写规则^  -  [L]

 #重定向HTTP:// WWW。只是HTTP://
 的RewriteCond%{HTTP_HOST} ^ WWW \。(。*)$ [NC]
 重写规则^ $ HTTP(*)://%1 / $ 1 [R = 301,L]

 的RewriteCond%{QUERY_STRING} ^ _escaped_fragment_ =
 的RewriteCond%{HTTP_HOST} ^ touchtyping.guru [NC]
 重写规则^快照%{REQUEST_URI} -en.html [L]

 的RewriteCond%{QUERY_STRING} ^ _escaped_fragment_ =
 的RewriteCond%{HTTP_HOST} ^(ES | PL | EN).touchtyping.guru [NC]
 重写规则^快照%{REQUEST_URI}  - %1.HTML [L]

 #改写一切以index.html来让HTML5状态的链接
 重写规则^的index.html [QSA,L]
 

解决方案

你有没有尝试添加一个特定的规则是什么?

 的RewriteCond%{QUERY_STRING} ^ _escaped_fragment_ =
 的RewriteCond%{HTTP_HOST} ^ touchtyping.guru [NC]
 重写规则^ $快照/指数en.html [L]
 


编辑:

尝试重新安排您的规则了一下:

  RewriteEngine叙述上

 #重定向HTTP:// WWW。只是HTTP://
 的RewriteCond%{HTTP_HOST} ^ WWW \。(。*)$ [NC]
 重写规则^ $ HTTP(*)://%1 / $ 1 [R = 301,L]

 的RewriteCond%{QUERY_STRING} ^ _escaped_fragment_ =
 的RewriteCond%{HTTP_HOST} ^ touchtyping.guru [NC]
 重写规则^(指数\ html的)?$快照/指数en.html [L]

 的RewriteCond%{QUERY_STRING} ^ _escaped_fragment_ =
 的RewriteCond%{HTTP_HOST} ^(ES | PL | EN).touchtyping.guru [NC]
 重写规则^(指数\ html的)?$快照/转位%1.HTML [L]

 #不要重写文件或目录
 的RewriteCond%{} REQUEST_FILENAME -f [OR]
 的RewriteCond%{} REQUEST_FILENAME -d
 重写规则^  -  [L]

 的RewriteCond%{QUERY_STRING} ^ _escaped_fragment_ =
 的RewriteCond%{HTTP_HOST} ^ touchtyping.guru [NC]
 重写规则^快照%{REQUEST_URI} -en.html [L]

 的RewriteCond%{QUERY_STRING} ^ _escaped_fragment_ =
 的RewriteCond%{HTTP_HOST} ^(ES | PL | EN).touchtyping.guru [NC]
 重写规则^快照%{REQUEST_URI}  - %1.HTML [L]

 #改写一切以index.html来让HTML5状态的链接
 重写规则^的index.html [QSA,L]
 

I use angular with html5 mode

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

and for that I have htaccess to handle google indexing

 # 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]

This redirects to appropriate snapshot for all the subpages, like eg:

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

but it doesn't work for the root domain like below, rendering the /index page, instead of redirecting to it's snapshot:

 http://touchtyping.guru/?_escaped_fragment_=

The snapshot exists, I tried hardcoded index-en.html there, but no success. Seems like htaccess doesn't catch the query string in this case, loading angular routing. How can I fix that?

UPDATE--------------------------------------

The whole htaccess file:

 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]

解决方案

Have you tried adding a specific rule for that?

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


EDIT:

Try re-arranging your rules a bit:

 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的:重定向根域为快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆