I want to use url rewrite for linux lighttpd.conf
but I can't get the right regular expression.
My web url is ip/cgi/aaa/bbb
and I want to rewrite the url path. My target is /var/www/cgi/aaa.cgi?par=bbb
I write the rule as "^/cgi/([^/]+)\\/(.*)?"=> "/var/www/cgi/$1.cgi?par=$2"
But somehow I can't get the parameter par
value.
Your issue is because of your anchoring at the beginning of the input.
^/cgi
..will not match ip/cgi
, because ip
is at the start.. not /cgi
. To fix it.. put ip
in front of what you have:
^ip/cgi/([^/]+)\/(.*)?
# ^^ this part
Below is the output once that change is made:
"^" matches at beginning of string. As your ip is dynamic, try to match from "cgi" as it is absolute.
I tried below input at http://gskinner.com/RegExr/ and worked fine.
/cgi/([^/]+)\/(.*)?
/var/www/cgi/$1.cgi?par=$2
ip/cgi/aaa/bbb
result is ip/var/www/cgi/aaa.cgi?par=bbb
If you don't want "ip" in result string, use
(.*)/cgi/([^/]+)\/(.*)?
/var/www/cgi/$2.cgi?par=$3
ip/cgi/aaa/bbb
result is /var/www/cgi/aaa.cgi?par=bbb (without ip)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.