10

我必须使用 SSI 获取 URL 和参数(仅使用 SSI),但我找不到任何解决方案。

例如:http ://www.test.com/abc.html?data=something

我必须得到参数“数据”的值。

4

2 回答 2

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" -->
于 2011-03-05T10:09:14.710 回答
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.

于 2010-12-17T17:51:44.777 回答