【问题标题】:Prerender.io subpages redirect to indexPrerender.io 子页面重定向到索引
【发布时间】:2015-09-21 13:29:24
【问题描述】:

我已遵循以下指南:

角度:

$locationProvider.html5Mode(true);

在 html 中,添加这个元标题:

<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 ^(.*)/$ $1 [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}$1 [P,L]

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

现在我的索引网站终于被谷歌收录了。

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

谁能告诉我我做错了什么?我已经尝试了数周,但未能提出解决方案:(

来自google-bot-simulator

【问题讨论】:

  • 假设 /products 不存在(不是真实文件),您的 htaccess 会将其重写为 /index.html。这是正常的行为,所以。你会拿什么来代替?

标签: apache .htaccess google-search


【解决方案1】:

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

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

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

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

试一试。另外,看看你的浏览器是否有一个“用户代理切换器”插件,它可以让你比通过谷歌工具更快地进行测试。

【讨论】:

  • 您不想通过他们的用户代理检测 Googlebot,因为这可能会因伪装而受到惩罚。为此,支持 escaped_fragment 协议。我不建议通过他们的用户代理检测 Googlebot。
【解决方案2】:

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

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

【讨论】:

  • 我的 htaccess 是空的
  • 顺便说一句,上面的代码应该在我的 htaccess 或我的 apache 配置中
  • 您能否将配置的 prerender 部分移动到 htaccess 的顶部,以便它首先执行并查看是否有任何改变?请随时将您的网址发送给我,以便我帮助测试。 todd@prerender.io
猜你喜欢
  • 2020-11-05
  • 1970-01-01
  • 1970-01-01
  • 2019-08-06
  • 1970-01-01
  • 2018-04-27
  • 2021-06-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多