Rewrite: how to check if header exists

I am trying to check if header does not exist then proxy to a login url else to a different url

Re-write / to /login if X-Login-Token

rewrite / {
    if  not  {>X-Login-Token}  is ""    #####  CHECK FOR EXISTENCE ####
    ##### The if condition does not have a exist operator, any alternatives ?
    to /login{path}
# Re-write / to /web_server
rewrite / {
    if  not {>X-Login-Token} is  "" 
    to /web_server{path}

Hi @pdhar, welcome to the Caddy community.

The form if not A is B isn’t implemented. Use the form if A not B instead.

Check the documentation for syntax and conditional usage:

1 Like

I checked those out, however it seems the conditions expect two operands A and B where exists check is for a single operand. Thanks anyway. I will try to use match with regex null ^$ and see if it works.

The zero value for a string in Golang is "", which you can use as your second operand.

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