用 htaccess 替换 URL 的一部分并在字符串中添加两个零

Replace part of the URL and add two zeros in string with htaccess

谁能帮我解决这个正则表达式,这样我就可以替换:

这个URL:

mydomain.com/artigos/8170-comooool

收件人:

mydomain.com/blog/817000-comooool

这是:

1: Replace the word `artigos` by `blog`
2: Add two zeros to the 4 digit number after the slash

我试过了:

RewriteRule ^artigos(\d{4}-.*) /blog/ [R=301,L]

但似乎没有任何效果。

您可以在 RewriteEngine On 行下方添加此重定向规则:

RewriteEngine On

RewriteRule ^artigos/(\d+)(-.*)$ /blog/0 [L,R=301,NE,NC]

我们必须使用 2 个单独的捕获组:第一个捕获 /artigos/ 之后的所有数字,第二个捕获之后的所有文本。