What's the best way to rewrite URLs as 301 redirects with the following conditions?
Sample old URLs to rewrite:
/c/garments-apparel/red-yellow-polka-dress-10_450
/c/shoes-and-accessories/black-suede-boots-02_901
Conditions:
- Change
c
tocategory
- Remove trailing number (including connecting dash) from URL (example:
-10_450
and-02_901
)
New URLs should be:
/category/garments-apparel/red-yellow-polka-dress
/category/shoes-and-accessories/black-suede-boots
Note that changes will be applied to an .htaccess file on a Wordpress environment.
You can have this rule just below
RewriteEngine On
line:you can use the regex
to replace the trailing numbers with "" (empty string) demo
then use the regex
and replace with /category/ demo