Forum Discussion

RahulK_74703's avatar
RahulK_74703
Icon for Nimbostratus rankNimbostratus
Sep 24, 2009

Q ? Rewrite rule

I'm trying to write a rule that will hit URI like:

 

 

/pages/auto-01111.html

 

/pages/healthy-living-01234.html

 

 

 

{[scan [HTTP::uri] {/pages/%[a-zA-Z0-9:]-%[0-9:].html} a b] == 2}

 

{ HTTP::uri "/pages/$a.aspx?ZipCode=$b" }

 

 

It's not working if there is two "-" in the URI, like "/pages/healthy-living-01234.html".

 

 

If add "{/pages/%[a-zA-Z0-9:\-]-%[0-9:].html} a b] == 2}", it doesn't hit.

 

 

Could you help ?

 

 

thanks
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    It's the exact scan command you were trying, but what about this:

     

     

    % scan /pages/auto-01111.html {/pages/%[^0-9]%[0-9:].html}

     

    auto- 01111

     

    % scan /pages/healthy-living-01234.html {/pages/%[^0-9]%[0-9:].html}

     

    healthy-living- 01234

     

     

    You could then use string range to trim off the last hyphen from the first match:

     

     

    % scan /pages/healthy-living-01234.html {/pages/%[^0-9]%[0-9:].html} a b

     

    2

     

     

    % set a [string range $a 0 end-1]

     

    healthy-living

     

     

    % echo "$a $b"

     

    "healthy-living 01234"

     

     

    Aaron