1

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

1
  • What version of Apache are you using? You should include that as a tag. Commented Jun 20, 2014 at 10:41

1 Answer 1

1

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 
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.