htaccess не перенаправляет индексную страницу в кеш prerender.io (но перенаправляет подстраницы)

Это работает: example.com/24

Это не так: example.com

Я не уверен, проблема в htaccess или в apache conf.

.htaccess код

        <IfModule mod_headers.c>
            RequestHeader set X-Prerender-Token "xxxxxxxxxxxxx"
        </IfModule>

        <IfModule mod_rewrite.c>
            RewriteEngine on

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

            Options +FollowSymLinks
            #RewriteRule ^api/(.*)$ http://vivule.ee/api/$1 [P,L]

            # Don't rewrite files or directories, but exclude adminer directory
            RewriteRule ^(adminer)($|/) - [L]
            RewriteCond %{REQUEST_FILENAME} -f
            RewriteRule ^ - [L]

            # Prerender.io stuff
            <IfModule mod_proxy_http.c>
                RewriteCond %{HTTP_USER_AGENT} Googlebot|bingbot|Googlebot-Mobile|Baiduspider|Yahoo|YahooSeeker|DoCoMo|Twitterbot|TweetmemeBot|Twikle|Netseer|Daumoa|SeznamBot|Ezooms|MSNBot|Exabot|MJ12bot|sogou\sspider|YandexBot|bitlybot|ia_archiver|proximic|spbot|ChangeDetection|NaverBot|MetaJobBot|magpie-crawler|Genieo\sWeb\sfilter|Qualidator.com\sBot|Woko|Vagabondo|360Spider|ExB\sLanguage\sCrawler|AddThis.com|aiHitBot|Spinn3r|BingPreview|GrapeshotCrawler|CareerBot|ZumBot|ShopWiki|bixocrawler|uMBot|sistrix|linkdexbot|AhrefsBot|archive.org_bot|SeoCheckBot|TurnitinBot|VoilaBot|SearchmetricsBot|Butterfly|Yahoo!|Plukkie|yacybot|trendictionbot|UASlinkChecker|Blekkobot|Wotbox|YioopBot|meanpathbot|TinEye|LuminateBot|FyberSpider|Infohelfer|linkdex.com|Curious\sGeorge|Fetch-Guess|ichiro|MojeekBot|SBSearch|WebThumbnail|socialbm_bot|SemrushBot|Vedma|alexa\ssite\saudit|SEOkicks-Robot|Browsershots|BLEXBot|woriobot|AMZNKAssocBot|Speedy|oBot|HostTracker|OpenWebSpider|WBSearchBot|FacebookExternalHit [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))(.*) http://service.prerender.io/http://vivule.ee/$2 [P,L]
            </IfModule>

            # Rewrite everything else to index.html to allow html5 state links
            RewriteRule ^adminer - [L,NC]
            RewriteRule ^ index.html [L]

        </IfModule>

Я тестирую это: https://developers.facebook.com/tools/debug/og/object/

Веб-страница с проблемой: http://vivule.ee/


person yodalr    schedule 30.05.2016    source источник


Ответы (2)


Хорошо, вот как я это решил. Оказывается, проблема заключается в настройке Apache 2.4, по какой-то причине он обходит серверы пререндеринга и обслуживает необработанный html с исходного сервера. Я решил эту проблему, добавив «DirectoryIndex» в файл htaccess. Параметры не добавляются, это устанавливает индекс страницы на http://example.com/.

Вот мой окончательный код:

        <IfModule mod_headers.c>
            RequestHeader set X-Prerender-Token "XXXXXXXXXXXX"
        </IfModule>

        <IfModule mod_rewrite.c>
            DirectoryIndex
            RewriteEngine on

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

            Options +FollowSymLinks
            #RewriteRule ^api/(.*)$ http://vivule.ee/api/$1 [P,L]


            # Prerender.io stuff
            <IfModule mod_proxy_http.c>
                RewriteCond %{HTTP_USER_AGENT} Baiduspider|DoCoMo|Twitterbot|TweetmemeBot|Twikle|Netseer|Daumoa|SeznamBot|Ezooms|MSNBot|Exabot|MJ12bot|sogou\sspider|bitlybot|ia_archiver|proximic|spbot|ChangeDetection|NaverBot|MetaJobBot|magpie-crawler|Genieo\sWeb\sfilter|Qualidator.com\sBot|Woko|Vagabondo|360Spider|ExB\sLanguage\sCrawler|AddThis.com|aiHitBot|Spinn3r|BingPreview|GrapeshotCrawler|CareerBot|ZumBot|ShopWiki|bixocrawler|uMBot|sistrix|linkdexbot|AhrefsBot|archive.org_bot|SeoCheckBot|TurnitinBot|VoilaBot|SearchmetricsBot|Butterfly|Yahoo!|Plukkie|yacybot|trendictionbot|UASlinkChecker|Blekkobot|Wotbox|YioopBot|meanpathbot|TinEye|LuminateBot|FyberSpider|Infohelfer|linkdex.com|Curious\sGeorge|Fetch-Guess|ichiro|MojeekBot|SBSearch|WebThumbnail|socialbm_bot|SemrushBot|Vedma|alexa\ssite\saudit|SEOkicks-Robot|Browsershots|BLEXBot|woriobot|AMZNKAssocBot|Speedy|oBot|HostTracker|OpenWebSpider|WBSearchBot|FacebookExternalHit [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))(.*) http://service.prerender.io/http://vivule.ee/$2 [P,L]
            </IfModule>

            # Don't rewrite files or directories, but exclude adminer directory
            RewriteRule ^(adminer)($|/) - [L]
            RewriteCond %{REQUEST_FILENAME} -f
            RewriteRule ^ - [L]

            # Rewrite everything else to index.html to allow html5 state links
            RewriteRule ^adminer - [L,NC]
            RewriteRule ^ index.html [L]

        </IfModule>
person yodalr    schedule 02.06.2016
comment
Уважаемый Yodalr, у меня проблема с тем, как узнать, что пререндеринг работает! У меня есть красная ошибка, которая говорит, что мы еще не видели запрос с вашим токеном Prerender. Мне нужно подождать некоторое время или после настройки моего файла .htaccess он исчезнет? Приятно отметить, что все 3 опции режима на сервере включены! Спасибо, что помогли мне как можно скорее. - person Hamed; 06.01.2019
comment
@Hamed, свяжитесь с пользователем prerender.io - stackoverflow.com/users/3450859/prerender-io он, кажется, разработчик пререндера - person yodalr; 07.01.2019

Это может соответствовать вашей домашней странице и обслуживать index.html до запуска конфигурации предварительного рендеринга.

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

Попробуйте переместить конфигурацию пререндера выше в вашем файле.

person Prerender.io    schedule 31.05.2016