.htaccess wildcard redirect 301

.htaccessredirect

i have to redirect many urls

the structure is this:

OLD URL

/category/product-18-name.aspx

NEW URL

product18name.php (is merely an example)

i wish to do a regex, if a user type /anyword/product-18-name.aspx i wish that user will go to product18name.php

in short, i wish that the word in the middle of 2 first slashes, example: /category/ that maybe a real category or any word to go to right page

so a user that type: /helloworld/product-18-name.apsx goes to product18name.php
or /sdjfkskfdns/product-18-name.apsx goes to product18name.php

Now my .htaccess is full of 301 redirects, like

Redirect 301 /electronic/peacemaker2_a5f89948-9f15-4606-9d5c-051d84a4c070.aspx http://www.site.com/product.php?id_product=23580

any help ? thanks

Best Answer

A rewrite rule to rewrite any-directory/product-18-name.aspx to product18name.php may look like this

RewriteRule ^(.*)/product-18-name.apsx /product18name.php