Reputation: 972
I need help with a RedirectMatch Regex directive.
I need the following URL to be redirected as follow :
RedirectMatch 301 ^/category/category-title/(.+)(!?/page/)$ http://example.com/product/category-title/$1
The result I want is to redirect to specified product title except if word page is found :
http://example.com/category/category-title/some-product-title-here
redirects to
http://example.com/product/category-title/some-product-title-here
The following would not match : http://example.com/category/category-title/page/23
EDIT :
I have a redirect loop with the following rules :
RedirectMatch 301 ^/categorie/boulangerie-et-patisserie/((?!/page/).+)$ http://recyclageindustriel.com/produit/boulangerie-et-patisserie/$1
RedirectMatch 301 ^/produit/boulangerie-et-patisserie/page/(.*)$ http://recyclageindustriel.com/categorie/boulangerie-et-patisserie/page/$1
Thanks for your help !
Upvotes: 2
Views: 795
Reputation: 784898
Your negative lookahead syntax is incorrect and it is placed wrongly also.
Try this:
RedirectMatch 301 ^/categorie/boulangerie-et-patisserie/(?!page/)(.+)$ /produit/boulangerie-et-patisserie/$1
RedirectMatch 301 ^/produit/boulangerie-et-patisserie/page/(.*)$ /categorie/boulangerie-et-patisserie/page/$1
Correct negative lookahead syntax is (?!page/)
.
Upvotes: 2
Reputation: 29453
In
http://example.com/category/category-title/.htaccess
include the rule:
RewriteCond %{REQUEST_URI} !^page/
RewriteRule ^(.+)$ http://example.com/product/category-title/$1 [R=301]
This translates as:
Only follow the next RewriteRule
, if the requested URI does not begin with page/
.
Upvotes: 0