【问题标题】:Remove index.php from prerender htaccess rewrite rule从 prerender htaccess 重写规则中删除 index.php
【发布时间】:2017-07-22 04:10:42
【问题描述】:

我正在使用 prerender.io javascript 中间件在我的网站上呈现 JS 页面。

htaccess中间件代码如下。

    RewriteCond %{HTTP_USER_AGENT} googlebot|bing|msnbot|yandex|yahoo|baidu|facebook|screaming|siteliner|ahrefsbot|dmca.com [NC,OR]
    RewriteCond %{QUERY_STRING} _escaped_fragment_
    RewriteCond %{HTTP:X-Prerender} !1

    # Only proxy the request to Prerender if it's a request for HTML
    RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.svg|\.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.example.com/$2 [P,L]

这个问题,至少在我的服务器上(但不是在其他一些服务器上)是 index.php 被添加到发送到服务的 url 中,这会导致错误。

例如:https://www.example.com/index.php

可以阻止吗?

例如:https://www.example.com/

谢谢。

【问题讨论】:

    标签: apache .htaccess prerender


    【解决方案1】:

    首先,您不想通过它们的用户代理检查 googlebot、bingbot 或 yandex,因为它们支持 _escaped_fragment_ 抓取协议。通过他们的用户代理检查它们可能会因伪装而受到惩罚。

    尝试更改此行:

    RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.svg|\.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.example.com/$2 [P,L]
    

    到这里:

    RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.svg|\.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))(index.php)?(.*) http://service.prerender.io/https://www.example.com/$3 [P,L]
    

    注意到 (index.php) 的添加了吗?并从 2 美元变为 3 美元。另外,不要忘记将 www.example.com 更改为您的域。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-15
      • 1970-01-01
      • 2017-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多