I need to rewrite urls and redirect the old requests to the new urls permanently. It's important to get the 301 recognized by Google to maintain the indexed pages.
Old Url: example.com/buy-productname-category-item/rest-of-url.html
New Url: example.com/productname-item/rest-of-url.html
Basically removing "buy-" and "category-" from the first part of the url. The rest of the urls all follow the same structure.
Options +FollowSymLinks
RewriteEngine On
# this rule sends root requests to index.html, which is then sent by the next rule to /php/page.php
# sends all requests for .html files to page.php for service
RewriteCond %{REQUEST_URI} !(.*)/sitemap.xml
RewriteCond %{REQUEST_URI} !(.*)/xml
RewriteCond %{REQUEST_URI} !(.*)/mockups
RewriteCond %{REQUEST_URI} !(.*)/php
RewriteCond %{REQUEST_URI} !(.*)/rss
RewriteRule ^(.*).html$ /php/page.php?uri=$1 [NC]
### ^ the most important rule
#---- remove buy- and ABC from urls
# the uri is being changed and page.php can't find it so it handles it as 404
RewriteRule buy-(.+)-ABC-123/(.+)$ /$1-123/$2 [L,R=301]
Please let me know why the above code is not working and also let me know if the [L,R=301] is actually what I need here.