我在 .htaccess 文件中使用 mod rewrite 将 URL 更改为更好的 URL,它会转换为:
http://domain.com?a=test&v=page&id=3
至
http://domain.com/test/page/3
使用这个条件
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?a=$1&v=$2&id=$3 [L]
如果 $1 == cart 且 $2 == home,我想做一些不同的事情
这里是一些使用 php if
条件的伪代码
if($1 == 'cart' && $2 == 'home'){
here I want to do a different rewrite rule
}else{
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?a=$1&v=$2&id=$3 [L]
}
知道我该怎么做吗?
最佳答案
2 个重写规则,首先是预定义的:
RewriteRule ^cart/home/([^/\.]+)?$ page2.php?id=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ index.php?a=$1&v=$2&id=$3 [L]
关于php - htaccess 重写 if 条件 if 变量等于某个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12802823/