Reputation: 6522
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.
Upvotes: 2
Views: 2040
Reputation: 11
This code works for me :
<!--#if expr="$REQUEST_URI = /([^?]+)\?.*/" -->
<!--#set var="URL_WITHOUT_QUERY_STRING" value="$1" -->
<!--#echo var='URL_WITHOUT_QUERY_STRING' -->
<!--#endif -->
Upvotes: 1
Reputation: 3804
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 ?
.
Upvotes: 3
Reputation: 3804
You could try to use the DOCUMENT_URI
variable instead:
<!--#echo var="DOCUMENT_URI" -->
SCRIPT_NAME
seems to work too:
<!--#echo var="SCRIPT_NAME" -->
Upvotes: 2