Adam Bickels
Adam Bickels

Reputation: 471

Regex in rewrite.xml

I'm writing new rule in rewrite.xml

i want an address (friendly url) like http://adam.com/search?q=123

will go to

http://adam.com/blablabla.aspx?q=123

i need to do it in this XML structure.

<ruleset r301="" rewrite="^/search(.*)">
    <rule type="rewrite" hndlr="search">
      <source>^/search(.*)</source>
      <target>/blablabla.aspx</target>
    </rule>
  </ruleset>

but it doesn't work well. can someone knows why ?

Upvotes: 2

Views: 219

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626929

You may use

^/search\b([^/.]*)/?$

and rewrite with /blablabla.aspx{R:1}. The /? is for an optional trailing slash - remove if not necessary.

The ^/search\b([^/.]*)/?$ pattern matches:

  • ^ - start of string
  • /search\b - a whole word /search
  • ([^/.]*) - Group 1 (later, references to as {R:1}) matching 0+ characters other than / and .
  • /? - 1 or 0 / symbols
  • $ - end of string.

Upvotes: 2

Related Questions