Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Including different files using SSI? |
|
Author |
|
jensdahlin
Joined: 18 Dec 2007 Posts: 2
|
Posted: Tue 18 Dec '07 16:22 Post subject: Including different files using SSI? |
|
|
I want to include different files based on a parameter sent via the URL.
If the URL is [...]program.shtml?param=value
I want to include value.inc
<!--#include virtual="value.inc" -->
However if the URL is [...]program.shtml?param=anothervalue
I want to include value2.inc
<!--#include virtual="value2.inc" -->
I can't seem to find a solution to this problem - at least not without using perl or something like that and I would like to make this as easy as possible. Any hints?
Best regards
Jens |
|
Back to top |
|
glsmith Moderator
Joined: 16 Oct 2007 Posts: 2268 Location: Sun Diego, USA
|
Posted: Tue 18 Dec '07 22:31 Post subject: |
|
|
Well, being that it doesn't read the query string I think you're out of luck. It does environment variables but all the SetEnvIf need would probably not be to your liking as well. |
|
Back to top |
|
tdonovan Moderator
Joined: 17 Dec 2005 Posts: 611 Location: Milford, MA, USA
|
Posted: Wed 19 Dec '07 0:31 Post subject: |
|
|
If you don't mind skipping the "param=" part of the query string, it becomes much easier.
Put this in your program.shtml page: Code: | <!--#include virtual="${QUERY_STRING}.inc" --> |
If you request [...]program.shtml?value, program.shtml will include the file value.inc
If you request [...]program.shtml?value2, program.shtml will include the file value2.inc
It might be a good idea to handle requests where there is no query string using default.inc.
For example: Code: | <!--#if expr=${QUERY_STRING} -->
<!--#set var="SELECTED_INCLUDE" value="${QUERY_STRING}" -->
<!--#else -->
<!--#set var="SELECTED_INCLUDE" value="default" -->
<!--#endif -->
<!--#include virtual="${SELECTED_INCLUDE}.inc" --> |
Hope this helps...
-tom- |
|
Back to top |
|
jensdahlin
Joined: 18 Dec 2007 Posts: 2
|
Posted: Wed 19 Dec '07 9:23 Post subject: |
|
|
Thanks!
I experimented with your idea and found out a solution that suited me better:
<!--First I set a variable as the QUERY_STRING-value -->
<!--#set var="qs" value="$QUERY_STRING" -->
<!--Then I include file depending on the value of this variable.-->
<!-- I have an else-statement in the end - default value if no criteria matches -->
<!--#if expr="$qs='param=one'" -->
<!--#include virtual="/one.inc" -->
<!--#elif expr="$qs='param=two'"-->
<!--#include virtual="/two.inc" -->
<!--#elif expr="$qs='param=three'"-->
<!--#include virtual="/three.inc" -->
<!--#else -->
<!--#include virtual="/one.inc" -->
<!--#endif -->
Using some kind of regexp it might even be possible to break out the value-part of the url-parameter but this will have to do right now.
Once more: thanks! |
|
Back to top |
|
|
|
|
|
|