.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.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进