我需要重写几个url,如果这些url没有结束某些单词。 例如,我需要重写下面的url
/category1/subcategory1/aproduct-url-title to /category1/fixedword/aproduct-url-title
重写不应该发生在下面的url上,因为这些链接以某些特定的词结束(view-all,p10,p20,p30,从低到高,从高到低) –
/category1/subcategory1/view-all /category1/subcategory1/p10 /category1/subcategory1/p20 /category1/subcategory1/low-to-high /category1/subcategory1/high-to-low
我试着用下面的规则没有成功 –
RewriteRule ^(category1|category2)\/(.*)\/(!p[0-9]+|view-all|low-to-high|high-to-low)$ /$1/fixedword/$3
我也试过以下规则 –
RewriteCond %{REQUEST_URI} !(p[0-9]+|view-all|low-to-high|high-to-low)$ RewriteRule ^(category1|category2)\/(.*)\/(.*)$ /$1/fixedword/$3
感谢你的帮助。
谢谢
您必须执行负面预测和捕获。
正确的RewriteRule将如下所示:
RewriteRule ^(category1|category2)\/(.*)\/((?!p[0-9]+|view-all|low-to-high|high-to-low).*)$ /product/detail/$3