我试图找到一个重写规则来删除破折号,后跟URL中间的任何数字(始终只在斜杠之前)。 示例:http://my.site.com/apples-256/golden-delicious/ 应该是:http://my.site.com/apples/golden-delicious/
我尝试了这个没有成功:
RewriteRule ^(.*)(-[0-9]+\/)(.*)$ $1/$2 [L]
答案 0 :(得分:1)
我似乎找到了规则:
# Rewrite old URLs with category IDs in the middle
RewriteRule ^(.*)(-[0-9]+)\/(.*) $1/$3 [R=301,L,R]
至少它对我有用。
现在我正在使用这两条规则来删除网址末尾的数字:
# 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]