Mod_rewrite替换url末尾的特定字符串

时间:2015-02-09 02:52:11

标签: .htaccess mod-rewrite

我需要用特定的id替换最后一个url。

我可以使用: -

RewriteRule ^tester-affiliate index.php?ID=8 [NC,L] # rewrite the affiliate url

如果网址只是domain.tid/tester-affiliate

但如果网址为domain.tid/category/product/tester-affiliate

,该怎么办?

我需要将网址写为domain.tid/category/product/index.php?ID=8

1 个答案:

答案 0 :(得分:1)

尝试:

RewriteRule ^(.*)tester-affiliate $1/index.php?ID=8 [L,NC]

tester-affiliate之前的任何内容都会被正则表达式(.*)捕获并使用$1进行反向引用。