Regex用Isapi重写替换两个条件下的空间



我正在为IIS使用Isapi Rewrite,我想为动态产品页面制作SEO友好的URL。

我需要以不同的方式替换两个查询字符串参数中的空格。

在第一个参数中,/s应替换为+在第二个例子中,所有的都应该替换为-

#seo. 2 conditions. split on _ delimiter.
RewriteRule ^Store/([^_]+)_([^/]+) Store/Details.aspx?id=$1&name=$2  [QSA,NC]
#replace spaces with + in first condition (doesn't work)
#RewriteRule ^Store/([^ws]+)s(.+)$ Store/Details.aspx?id=$1+$2  [QSA, NC]
#replace spaces with dash in second condition ???

示例

Store/NP SP_name name
//$1: NP+SP
//$2: name-name
// output: Store/NP+SP_name-name
Store/mn%2098%20765_name%20name%20name
//$1: mn+98+765
//$2: name-name-name
//output: Store/mn+98+765_name-name-name

前几天我也做过类似的smth,但有一个更简单的任务,只有一种类型的替换。尝试使用以下方法进行基本重定向(如果有效,我们会想到一个更复杂的多参数场景):

RewriteRule ^Store/(.+)s([^_]+)_(.+)s(.+) /Store/$1+$2_$3-$4  [NC,R=301,L]

确保你在现有重写的基础上加上了。

最新更新