Get URL and parameters with SSI
Asked Answered
G

2

10

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".

Gunfire answered 17/9, 2010 at 6:20 Comment(0)
R
25
<!-- 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" -->
Remotion answered 5/3, 2011 at 10:9 Comment(2)
I would change /data to /\bdata (\b is a word boundary) to avoid matching variables like iamnotdata.Heger
Doesnt work for me. Variable always is empty.Interlude
N
0

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.

Nela answered 17/12, 2010 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.