문제

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
도움이 되었습니까?

해결책

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

RewriteRule ^Store/([^_]+)_([^/]+) Store/Product.aspx?sku=$1&name=$2 [QSA,NC]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top