mesnicka
mesnicka

Reputation: 2548

Get URL and parameters with SSI

I have to get URL and parameters with SSI (only with SSI), but I can't find any solution.

For example: http://www.test.com/abc.html?data=something

And I have to get value of parameter "data".

Upvotes: 10

Views: 13571

Answers (2)

ahgood
ahgood

Reputation: 1937

<!-- set default value for SSI variable "data" -->    
<!--#set var="data" value="" -->

<!-- get "data" value from URL --> 
<!--#if expr="$QUERY_STRING = /data=([a-zA-Z0-9]+)/" -->
<!--#set var="data" value="$1" -->
<!--#endif -->

<!-- print the "data" value -->     
<!--#echo var="data" -->

Upvotes: 25

tjm
tjm

Reputation: 7550

old question I know, but I just came across it while doing some SSI stuff myself. I'm sure you've fixed your problem by now, but if this doesn't help you, perhaps it will someone else. I'm assuming the server is Apache. (If not, then I guess this isn't going to work!)

First the disclaimer! I'm by no means an apache, sed, or regex master, so I'm sure what follows can be improved, but it may be a start. It just prints the page relative to the base of the site and the parameter of the data query.

<!--#echo var="DOCUMENT_URI" -->
<!--#exec cmd="echo '$QUERY_STRING' | sed -n 's/\([^&]*&\)*data=\([^&]*\).*/\2/p'" --> 

I found a list of apache environment variables here: http://www.zytrax.com/tech/web/env_var.htm, and to find out what you can do with this stuff once you've retrieved it look here: http://httpd.apache.org/docs/2.0/howto/ssi.html.

Edited to make it print nothing rather than the whole string when no data attribute is found.

Upvotes: 0

Related Questions