.htaccess批量数字ID跳转规则错在哪里?

我想做一个批量301跳转,通过.htaccess

计划实现:domain.com/123/ 301重定向到 domain.com/123.html

自己写了一个不对,求高手帮看看错在哪里,如下。

RewriteEngine On
RewriteRule ^([0-9]+)/$ /([0-9]+).html$ [L,R=301]

谢谢了。

阅读 4.1k
1 个回答

Change your second line to
RewriteRule ^([0-9]+)/$ /$1.html [L,R=301]

This works because the $1 refers to the matched section within the parenthesis of your regex.