Question

I have a url for ex: http://dominename:port/first/1/second/2/third/3 and want to rewrite to http://dominename:port/first=1/second=2/third=3. I can get to first and get 1. But for two and three how can I get it?

below is my code to get first:

 <rule>
    <from>^/first/(.*)$</from>
    <to type="forward">/dominename:port/first=1</to>
</rule>

Thanks!

Was it helpful?

Solution

You access the regular replacement expressions by $1 , $2, ...

<rule>
    <from>^/first/(.*)/second/(.*)/third/(.*)$</from>
    <to type="forward">/first=$1/second=$2/third=$3</to>
</rule>

But that will not work, because you can not have = in the path of an url!

So what you may should do is this:

<rule>
    <from>^/first/(.*)/second/(.*)/third/(.*)$</from>
    <to type="forward">something?first=$1&second=$2&third=$3</to>
</rule>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top