reactjs - .htaccess 机器人代理

标签 reactjs .htaccess seo prerender

我刚刚用 create-react-app 写了一篇博客。除此之外,我还编写了一个小型服务,该服务将在服务器上使用 chrome 为 Google 或 Facebook 等爬虫呈现网站。

所以我有 http://example.com/path-to-page 应该提供给普通用户,还有 http://myprerenderer.com/render/http ://example.com/path-to-page 应提供给爬虫等。

这是我的 .htacces 目前的样子:

RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]

# redirect non www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]

# One year for image files
<filesMatch ".(jpg|jpeg|png|gif|ico|svg)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>

# One month for css and js
<filesMatch ".(css|js)$">
Header set Cache-Control "max-age=2628000, public"
</filesMatch>

这适用于我访问的每个 url 都由 react 应用程序 index.html 提供服务(顺便说一句,我正在使用 react 路由器。)。

现在,我需要如何针对这种情况调整我的 .htacces: 爬虫访问该网站,被重定向(或代理?)到预呈现器,然后预呈现器使用 chrome 为网站提供服务 - 但如果该网站已经被预呈现服务访问过,则不应再进行重定向。

谢谢!

最佳答案

您可能想要添加类似于 Prerender.io .htaccess 的内容来检测爬虫和代理(而不是重定向)对您的预呈现服务器的请求:

https://gist.github.com/thoop/8072354

关于reactjs - .htaccess 机器人代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49488466/

相关文章:

php - 在 Windows 7 中创建的 .htaccess 文件,但在 Ubuntu 12.10 中不起作用

WordPress 和 SEO : how to mask a path/pull content from another domain

reactjs - prop `children` 在 `AppBar` 中被标记为 required,但其值为 `undefined`

javascript - 将函数从纯 React 转换为 Redux React

javascript - Nextjs 中的样式组件延迟设置属性

javascript - 使用 React 时我应该使用什么来代替 document.queryselector()?

apache - 将通配符子域重定向到子目录,而不更改地址栏中的 URL

php - 使用 htaccess 从 URL 中删除文件夹名称

seo - 我的自然谷歌流量怎么了?

seo - Google 中的标题与源代码不同?