在 htaccess 文件中安装预渲染令牌

Installing Pre-render Token in htaccess file

我搜索了几天,但安装 prerender.io 令牌的 htaccess 文件仍然有问题。保存并测试所有类型的 htaccess 格式后,我收到此消息:

We haven't seen a request with your Prerender token yet. Click here to see how to install the token in your middleware.

实际上所有页面都被缓存了!我的项目是 ReactjsCodeigntier,在 Apache.

上共享主机

我有一个这样的 htaccess 文件:

# this section for forcing https and www
RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://www.mokaab.com/ [R,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/ [R=301,L]

#  this is the code wich provided on Prerender website
<IfModule mod_headers.c>
    RequestHeader set X-Prerender-Token "TOKEN"
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    <IfModule mod_proxy_http.c>
        RewriteCond %{HTTP_USER_AGENT} googlebot|bingbot|yandex|baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
        RewriteCond %{QUERY_STRING} _escaped_fragment_

        # Only proxy the request to Prerender if it's a request for HTML
        RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.m4v|\.torrent|\.ttf|\.woff))(.*) http://service.prerender.io/https://www.mokaab.com/ [P,L]
    </IfModule>
</IfModule>

# this is for avoiding 404 page when refreshing page on React apps
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

而且我换了地方还是有问题! 然后我将以下元标记放在 Head 部分:

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

我认为问题出在 htaccess 上。

.htaccess 文件是正确的!问题出在主机配置上! 必须在每种类型的主机上启用这些配置:

mod_headers.c
mod_rewrite.c
mod_proxy_http.c

显然前两个选项在普通主机上启用,但最后一个选项需要 SSH,这是不可用的!