.htaccess 重写规则,用于去除 URL 中间的破折号加号



我正在尝试找到一个重写规则来去除破折号,后跟URL中间的任何数字(总是只在斜杠之前(。示例:http://my.site.com/apples-256/golden-delicious/应为:http://my.site.com/apples/golden-delicious/

我试过这个没有成功:

RewriteRule ^(.*)(-[0-9]+/)(.*)$ $1/$2 [L]

似乎我找到了规则:

# Rewrite old URLs with category IDs in the middle
RewriteRule ^(.*)(-[0-9]+)/(.*) $1/$3 [R=301,L,R]

至少它对我有用。

现在我正在使用这 2 条规则来去除 URL 末尾的数字:

# Rewrite old URLs with category IDs at the end
RewriteCond %{REQUEST_URI} ^(.*)(-[0-9]+)$
RewriteRule .* %1 [R=301,L]
# Rewrite old URLs with category IDs in the middle
RewriteRule ^(.*)(-[0-9]+)/(.*) $1/$3 [R=301,L,R]

最新更新