Forum Moderators: phranque

Message Too Old, No Replies

Use HTTP status code in SSI conditional statement?

         

cschults

12:09 am on Mar 10, 2012 (gmt 0)

10+ Year Member



Is it possible to check the HTTP status code in a SSI conditional statement? Basically, I want to include another file if the status code is a 404 or 403.

When I do a printenv I don't see any variable that I can use.

lucy24

3:00 am on Mar 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I get the 403. (Well, on the deeper level I don't, but never mind that.)

I don't get the 404. Status 404 means the requested page doesn't exist at all, so where would the SSI go?

cschults

10:53 pm on Mar 11, 2012 (gmt 0)

10+ Year Member



The file where the SSI conditional would go is in an include file that is used by all pages on the website. This include file mostly contains the code within the <head> element. If the request is for an error page, I want to do something different in the <head> element.

g1smd

11:26 pm on Mar 11, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Apache has its own ErrorDocument mechanism for serving a particular file when there's an error.

cschults

12:03 am on Mar 12, 2012 (gmt 0)

10+ Year Member



Sorry I haven't been clear. I have a file, let's say 404.html, that is is the designated 404 error page per the ErrorDocument directive.

404.html, like all the other pages on the site, includes the header file that we'll call head.inc.

In head.inc, I want to add a SSI conditional like so (assuming it is possible):

<!--#if expr="$HTTP_STATUS = 404" -->
[do something]
<!--#endif -->

Does a variable like this (HTTP_STATUS) exist? I'm assuming not since my searching hasn't revealed one, but I thought I'd ask the group.

lucy24

12:41 am on Mar 12, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think you're making it more complicated and time-consuming-- both for yourself and for the server-- than it needs to be.

Server receives a request for 404 page. Under what circumstances would HTTP_STATUS not be 404? Are you allowing for people who deliberately ask for the 404 page by name? Or is the 404 page shared by other responses like 410?

That is: What's the important variable? The exact status, or the name of the page requesting the header? Seems like it would be less trouble to include the special material in the 404 page itself, rather than have the server run an extra test every time it puts together a page.

g1smd

12:47 am on Mar 12, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If the calling file is 404.html then the status code is obviously 404. You don't need to test the status, just know which file has issued the call.

Do people still use SSI? This stuff is so much easier and flexible with PHP.

cschults

5:53 pm on Mar 12, 2012 (gmt 0)

10+ Year Member



So, I just realized the page I'm troubleshooting with is a Drupal generated page (Drupal powers only part of our site.) After testing on a non-Drupal page, I see there is plenty to work with.

Most notably, there is the REDIRECT_STATUS variable, as documented here:

[httpd.apache.org...]

Plus, there are plenty of environment variables that reference the 404 file name as well.

With the Drupal pages, the PHP virtual() function is being used to include the header include. And due to the way that PHP sets environmental variables, the ones I need aren't set in my header include.