php - htaccess 重写 if 条件 if 变量等于某个字符串

标签 php .htaccess mod-rewrite

我在 .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/

相关文章:

javascript - 重定向 php 文件,无论 url 之后输入什么内容

php - 使用 php 并从 mySQL 调用值我试图调用包含 METAL GOLD 的每 16 行

php - 如何不让包裹路线重载主要路线?

.Htaccess 重定向的正则表达式

apache - 如何在重写规则上设置引用者?

.htaccess - 默认添加语言子目录 "sv/"(重定向)

php - 查找数组中未出现的最小正整数

python - 在 MacOS Sierra 中的 Apache 上执行 python 脚本

php - Apache mod-rewrite htaccess - 带参数的动态 url

apache - mod_rewrite 多个问号