Question

I am using Isapi Rewrite for IIS, and I want to make SEO friendly URLs for a dynamic product page.

I need to split the SKU from the product name in a single query string parameter. The SKU is always the first part, and is followed by an underscore. Everything that comes after the underscore is the product name. The product name uses dashes between words.

This is what I have so far and it just returns the whole query string in a single parameter. I need to split it on the underscore as below so that I get two values $1 and $2.

RewriteRule ^Store/([^/]+) Store/Product.aspx?sku=$1&name=$2  [QSA,NC]
  • Store/1234_name-name
  • //$1: 1234
  • //$2: name-name

  • Store/mn98765_name

  • //$1: mn98765
  • //$2: name

  • Store/sk000p9_name-name-name

  • //$1: sk000p9
  • //$2: name-name-name
Était-ce utile?

La solution

You want to capture the two groups with two separate parens. Try this:

RewriteRule ^Store/([^_]+)_([^/]+) Store/Product.aspx?sku=$1&name=$2 [QSA,NC]
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top