Htaccess rule for url not ending with certain words

.htaccessmod-rewriteregular expressions

I need to rewrite few urls if those url not ending with certain words. For example, i need to rewrite following url

/category1/subcategory1/aproduct-url-title
to
/category1/fixedword/aproduct-url-title

the rewrite should not takes place for the following urls as these are ending with certain specific words(view-all, p10, p20, p30, low-to-high, high-to-low) –

/category1/subcategory1/view-all
/category1/subcategory1/p10
/category1/subcategory1/p20
/category1/subcategory1/low-to-high
/category1/subcategory1/high-to-low

I've tried with following rule with no success –

RewriteRule ^(category1|category2)\/(.*)\/(!p[0-9]+|view-all|low-to-high|high-to-low)$ /$1/fixedword/$3

I've tried with following rules too –

RewriteCond %{REQUEST_URI} !(p[0-9]+|view-all|low-to-high|high-to-low)$
RewriteRule ^(category1|category2)\/(.*)\/(.*)$ /$1/fixedword/$3

Appreciate your help.

Thanks

Best Answer

You must perform a negative lookahead and capture.

The correct RewriteRule will look something like this:

RewriteRule ^(category1|category2)\/(.*)\/((?!p[0-9]+|view-all|low-to-high|high-to-low).*)$ /product/detail/$3