I have a lot of URLs like this: www.mywebsite.com/blog/item/1021-le-foreste.html that becomes, after SEF changes, like this: www.mywebsite.com/blog/le-foreste.html How can I write an .htaccess rule that say something like: where you find an URL with "item" word and ID number redirect to the same URL without "item" word and ID number, please? Thanks a lot.
1 Answer
Add this line to the very beginning of your .htaccess file:
RedirectMatch 301 /blog/item/(\d+)-(.*) /blog/$2
Explanation:
- This part
(\d+)
matches any number immediately after/blog/item/
- This part
(.*)
matches anything after the first dash. $2
represents what(.*)
matches, which is anything after the number and the hyphen (note that$1
will be the number, which is 1021 in the case of your example above)
-
1