AxelS
AxelS

Reputation: 329

switch case (or if else) to load a file with include in SSI and QUERY_STRING?

In PHP I can use switch case for using a simple function:

<?php
switch($_SERVER['QUERY_STRING']) {

case 'example1':
include 'example1.php';
break;

case 'example2':
include 'example2.php';
break;

case 'example3':
include 'example3.php';
break;

default:
include 'example1.php';
break;
}
?>

But how look it for SSI?

My not working example: (Note: SSI is working with my Apache ;-) )

<!--#if expr="$QUERY_STRING = 'example1'" -->
    <!--#include virtual="example1.html" -->
<!--#elif expr="$QUERY_STRING = 'example2'" -->
    <!--#include virtual="example2.html" -->
<!--#elif expr="$QUERY_STRING = 'example3'" -->
    <!--#include virtual="example3.html" -->
<!--#else -->
    <!--#include virtual="example1.html" -->
<!--#endif -->

I get only an error message:

[an error occurred while processing this directive]

Thank you in advance :-)

Upvotes: 0

Views: 223

Answers (2)

user9549415
user9549415

Reputation:

Try using

<!--#if expr="v('QUERY_STRING') = '/example1'" -->

You shouldn't need the legacy parser turned on for that.

Upvotes: 0

AxelS
AxelS

Reputation: 329

OK, I found following for .htaccess and my example works...

SSILegacyExprParser on

But exist a valid code without to use this snippet?

Sources:

Upvotes: 0

Related Questions