2

There is incredibly little documentation on how SSI directives work! But I'm following very simple examples and can't seem to adjust them to my purposes without throwing an error. What I want to do is display a custom 404 that differs based on if the user typed the URL (No HTTP_REFERER) or if there was a link from somewhere else.

Using this:

<!--#echo var="HTTP_REFERER" -->

with a fake manually typed uri I get this output:

(none)

as expected. So I set up this little test:

<!--#if var="HTTP_REFERER = (none)" -->
Yep
<!--#else -->
Nope
<!--#endif -->

I get this:

[an error occurred while processing this directive] Yep

I've tried other formats that I found:

<!--#if expr="${HTTP_REFERER} = (none)" -->

<!--#if expr="$HTTP_REFERER = (none)" -->

And a few others I don't recall right now, but they all result in the same thing... they print "yep" and then the error. if I remove the parenthesis surrounding "none", the error is gone and it correctly says "nope" but that doesn't really help because the the parenthesis are part of the string. That screams to me that perhaps one or both of the () have to be escaped, so I tried every combination of that and I either get the error or it fails the test.

Shockingly poor documentation on this topic that I can find. I realize it is ancient tech, but cPanel still uses it for custom error pages. I just want to make my error page a little smarter.

Or, is there just a better way?

bcsteeve
  • 973
  • 9
  • 22

2 Answers2

2

Lol. As usual, I figure it out seconds after posting.

It finally occurred to me that (none) is probably special. So I should be testing if the variable is set at all. This is the valid test:

<!--#if expr="${HTTP_REFERER}"-->
yep
<!--#else -->
Nope
<!--#endif -->
bcsteeve
  • 973
  • 9
  • 22
2

A good example of SSI usage is Adamant Analytics. An answer to your question is:

<!--#if expr="$HTTP_REFERER" -->
  <!--#set var="UTM_REFERER" value="$HTTP_REFERER" -->
<!--#endif -->
Valentin Podkamennyi
  • 7,161
  • 4
  • 29
  • 44