2016-11-15 160 views
0

我使用Angular JSSEO目的我将所有抓取请求重定向到静态html页面内容。.htaccess重定向到无限循环

我使用Apache服务器,以便在.htaccess文件我已经写:

RewriteEngine On 
RewriteCond %{HTTP_USER_AGENT} Googlebot [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} facebookexternalhit [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} Twitterbot [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} Baiduspider [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} MetaURI [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} mediawords [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} FlipboardProxy [NC,OR] 
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*?)\/*$ 
RewriteRule ^(.*)$ snapshots/$1.html [R=301,L] 

但它趋于无穷大重定向。

请转到这里:http://www.redirect-checker.org/index.php并输入链接为:http://templatic.net/test/job_category/mobile并选择搜索引擎作为Googlebot所以它会重定向到这样的:

enter image description here

所以,请帮我制止这种...

回答

0

一旦有任何RewriteCond匹配,并且请求test/job_category/mobile被重写为test/snapshots/job_category/mobile.html,则重写的请求将被交还给URL解析引擎,规则集将从头开始再次运行。

这一次,它将再次匹配HTTP_USER_AGENT,并改写为test/snapshots/snapshots/job_category/mobile.html.html,并送回来,并再次被改写,等等

的解决办法是,在你的重写规则,防止重写如果要求已开始snapshots/

RewriteEngine On 
RewriteCond %{HTTP_USER_AGENT} Googlebot [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} facebookexternalhit [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} Twitterbot [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} Baiduspider [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} MetaURI [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} mediawords [NC,OR] 
RewriteCond %{HTTP_USER_AGENT} FlipboardProxy [NC,OR] 
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*?)\/*$ 
RewriteRule ^(?!snapshots/)(.*)$ snapshots/$1.html [R=301,L]