如果某些 URL 不是以某些单词结尾,我需要重写这些 URL。例如,我需要重写以下 URL
/category1/subcategory1/aproduct-url-title
to
/category1/fixedword/aproduct-url-title
不应重写以下网址,因为这些网址以某些特定词语结尾(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
感谢你的帮助。
谢谢
答案1
您必须执行负向前瞻和捕获。
正确的RewriteRule
看起来应该是这样的:
RewriteRule ^(category1|category2)\/(.*)\/((?!p[0-9]+|view-all|low-to-high|high-to-low).*)$ /product/detail/$3