Proxy request to Prerender


(Joery) #1

Hello,

I have an Angular.js website and I am trying to proxy requests to Prerender when the user agent indicates it is a bot.

User agent regex: /bot|googlebot|crawler|spider|robot|crawling/i
Should proxy request to Prerender: http://localhost:3000/render?url=https://www.example.com/about

Is this possible?

Thank you.


(Matthew Fay) #2

You could try something like this:

example.com {
  rewrite {
    if_op or
    if {>User-Agent} has bot
    if {>User-Agent} has googlebot
    if {>User-Agent} has crawler
    if {>User-Agent} has spider
    if {>User-Agent} has robot
    if {>User-Agent} has crawling
    to /render?url={scheme}://{host}{uri}
  }
  proxy /render localhost:3000
}

That’s assuming that the url query should be dynamic. If not, replace {scheme}://{host}{uri} with the exact static URL you want it to use for the url query.

https://caddyserver.com/docs/rewrite
https://caddyserver.com/docs/proxy
https://caddyserver.com/docs/placeholders


(system) #3

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.