Prerender.io 个子页面重定向到索引

Prerender.io subpages redirect to index

我遵循了以下指南:

在angular中:

$locationProvider.html5Mode(true);

在 html 中,添加此元 header:

<head>
    <meta name="fragment" content="!">
</head>

配置 Apache:

  RewriteEngine On
# If requested resource exists as a file or directory
  # (REQUEST_FILENAME is only relative in virtualhost context, so not usable)
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
    # Go to it as is
    RewriteRule ^ - [L]

  # If non existent
    # If path ends with / and is not just a single /, redirect to without the trailing /
      RewriteCond %{REQUEST_URI} ^.*/$
      RewriteCond %{REQUEST_URI} !^/$
      RewriteRule ^(.*)/$  [R,QSA,L]      

  # Handle Prerender.io
    RequestHeader set X-Prerender-Token "YOUR_TOKEN"

    RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
    RewriteCond %{QUERY_STRING} _escaped_fragment_

    # Proxy the request
    RewriteRule ^(.*)$ http://service.prerender.io/http://%{HTTP_HOST} [P,L]

  # If non existent
    # Accept everything on index.html
    RewriteRule ^ /index.html

现在我的索引站点终于被 google 选中了。

然而,每当我尝试访问我的子站点时,它都会告诉我它已被重定向到 index.html

谁能告诉我我做错了什么?我已经尝试了几个星期,但一直未能想出解决方案:(

来自google-bot-simulator

你的 htaccess 以前是什么样子的?我认为这就是为什么您的子域都显示 index.html:

的原因
# If non existent
    # Accept everything on index.html
    RewriteRule ^ /index.html

您正在使用 Googlebot 测试您的网站,但该用户代理不在您的重写规则正在寻找的可能用户代理列表中。

RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]

上面列出了所有将被代理到 prerender.io 的机器人。更具体地说,它仅列出足以检测到它们的用户代理部分。如果您添加 'googlebot' 那么它也会匹配。或者可能只是 'bot' 用于测试目的。

RewriteCond %{HTTP_USER_AGENT} bot|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]

试一试。另外,看看您的浏览器是否有一个 'User Agent Switcher' 插件,可以让您比使用 google 工具更快地进行测试。