0

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

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

在第一个参数中,\s 应替换为 + 在第二个参数中,所有 \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/([^\w\s]+)\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
4

1 回答 1

0

前几天我也做过类似的事情,但是有一个更简单的任务,只有一种替换。尝试使用以下基本重定向(如果可行,我们将考虑更复杂的多参数场景):

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

确保你在现有的重写之上。

于 2012-07-25T08:36:37.117 回答