Search code examples
regexssi

How to get SSI variable REQUEST_URI without query parameters


I'm trying to get the pathname part of the REQUEST_URI, without the query parameters. I need to do this in raw SSI, without any PHP or anything.

If I do something like <!--#echo var="REQUEST_URI" -->, that will output the pathname plus the query parameters, so if the browser URL shows http://example.com/foo.html?bar, that would return /foo.html?bar. But I need to return only /foo.html. Is there a way to do that directly inside an echo statement?

Note: It needs to use the requested uri only. The actual file paths on the server are very different and I cannot display those.


Solution

  • I don't have a running nginx with SSI around, so i am just guessing here. But maybe you can try to use a regular expression to extract what you want. Maybe something like this:

    <!--# if expr="$REQUEST_URI = /(.+)\?.*/" -->
        <!--# echo var="1" -->
    <!--# endif -->
    

    I am not sure about the \ before the ?.