0

Can anyone help me with this regular expression so I can replace:

This URL:

mydomain.com/artigos/8170-comooool

To:

mydomain.com/blog/817000-comooool

This is:

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

I tried:

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

but nothing seems to work.

2
  • Please show your current .htaccess in question Commented Aug 5, 2021 at 19:15
  • 1
    @anubhava I'm trying a lot of stuff like: RewriteRule ^artigos(\d{4}-.*) /blog/$1 [R=301,L] - but nothing seems to work Commented Aug 5, 2021 at 19:17

1 Answer 1

0

You can add this redirect rule just below RewriteEngine On line:

RewriteEngine On

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

We have to use 2 separate capture groups: 1st to capture all digits after /artigos/ and 2nd to capture all text beyond that.

Sign up to request clarification or add additional context in comments.

2 Comments

YES! You got it again! How did you learn so much about this? I find it really tough!
Most of this is regular expressions and then some technical details of mod_rewrite

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.