Reputation: 642
How Can I redirect this pattern
example.com/fruits/7285/good-slug","id":"33b4","favicon_link":"https:/i.pinimg.com/fa/9.png
to this:
example.com/fruits/7285/good-slug
Tried:
RewriteEngine on
RewriteRule ^(fruits/\d+/[\w-]+). /$1 [R=301,L,NC,NE]
But it redirects too much.
Pinterest referring such URL(abc.com/fruits/123/slug) by adding some arrays after my URL, I do not know how, so I need to redirect to my actual one.
Upvotes: 1
Views: 46
Reputation: 785471
You may use this redirect rule with a possessive quantifier:
RewriteRule ^(fruits/\d+/[\w-]++). /$1 [R=301,L,NC,NE]
[\w-]++
matches longest possible string matching a word or hyphen characters without any backtracking.
On the other hand ^(fruits/\d+/[\w-]+).
will cause a redirect loop because regex engine backtracks to allow a match of a single character after [\w-]+
pattern.
Upvotes: 2