6

I set up prerender.io for CRA and it works well, but when bot hits URL without parameters it puts in the end of URL - string ".var"

enter image description here

I tried variations of (.*) but it seems not working. Any ideas?

Here is .htaccess file

Options +FollowSymLinks
RewriteEngine On

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

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

<IfModule mod_headers.c>
    RequestHeader set X-Prerender-Token "TOKEN"
    RequestHeader set X-Prerender-Version "prerender-apache@2.0.0"
</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\/0\.|pinterestbot|slackbot|vkShare|W3C_Validator|whatsapp [NC,OR]
        RewriteCond %{QUERY_STRING} _escaped_fragment_
        RewriteCond %{REQUEST_URI} ^(?!.*?(\.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|\.svg))

        RewriteRule ^(index\.html|index\.php)?(.*) https://service.prerender.io/%{REQUEST_SCHEME}://%{HTTP_HOST}/$2 [P,END]
    </IfModule>
</IfModule>
Tiffany
  • 487
  • 2
  • 13

1 Answers1

2

Lately @MrWhite gave us another, better and simple solution - just add DirectoryIndex index.html to .htaccess file will do the same.


From the beginning I wrote that DirectoryIndex is working but NO! It seems it's working when you try prerender.io, but in reality it was showing website like this:

enter image description here

and I had to remove it. So it was not issue with .htaccess file, it was coming from the server.

What I did was I went into WHM->Apache Configurations->DirectoryIndex Priority and I saw this list

enter image description here

and yes that was it!

To fix I just moved index.html to the very top second comes index.html.var and after rest of them.

I don't know what index.html.var is for, but I did not risk just to remove it. Hope it helps someone who struggled as me.

Tiffany
  • 487
  • 2
  • 13
  • Using `DirectoryIndex` without any arguments is undocumented ([according to the docs](https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryindex) it's not strictly valid). However, the behaviour would seem to be the same as `DirectoryIndex disabled`. (Although the fact that you appeared to be seeing an "external redirect" would perhaps suggest that [`DirectoryIndexRedirect on`](https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryindex) was set? This defaults to `off` and can be set to `off` in `.htaccess`.) – MrWhite May 13 '21 at 01:26
  • You are right I know, I realized later, but I'm going back and forth with their support and I don't have solution yet. As soon as I'll have it I'll update this post. Thank you – Tiffany May 17 '21 at 17:28
  • 1
    Thanks for the follow-up. To clarify... "I wrote that DirectoryIndex is working" - What you did before completely disabled the `DirectoryIndex`. "It seems it's working when you try prerender.io" - prerender.io probably just saw the 200 OK response and assumed it was working. The output you were seeing (a directory listing) was because `Options Indexes` is enabled (probably in the server config), otherwise the request would have resulted in a 403 and prerender.io would have probably failed. `Indexes` should not be enabled. You should set `Options +FollowSymLinks -Indexes` in `.htaccess`. – MrWhite Jun 05 '21 at 01:05
  • 2
    "So it was not issue with .htaccess file" - Although this could have been resolved using `.htaccess`. What you eventually did in the server's WHM control panel is effectively the same as setting `DirectoryIndex index.html` in `.htaccess` (which overrides the server config). – MrWhite Jun 05 '21 at 01:11
  • @MrWhite you are absolutely right! Just I was struggled so much and there was nobody to help. I asked prerender.io support, web hosting support, nobody even gave me a clue. So finally I ended up doing this thing in WHM. Thank you for .htaccess solution :) Obviously you could help but because of my lack of experience I even couldn't explain that well for someone to understand... Thank you – Tiffany Jun 07 '21 at 18:20