首页 > 解决方案 > 当我使用多个参数时,无法使用 .htaccess rewriteRule 重定向到特定页面

问题描述

我的 .htaccess 行是

RewriteRule ^notifications/([a-zA-Z0-9-_]+) notifications.php?type=$1 [NC,L]

RewriteRule ^notifications/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+) notifications.php?type=$1&cat=$2 [NC,L]

即使我提供了 localhost/notifications/competative/upsc,也只有第一个重写规则有效

如果我正在回显它,则会将错误作为未定义的索引“猫”抛出。

这个工作正常 localhost/notifications/competative/

标签: phphtmlcssmysql.htaccess

解决方案


试试下面的规则,我们用'$'符号来表示我们规则的边界。

RewriteRule ^notifications/([a-zA-Z0-9-_]+)$ notifications.php?type=$1 [NC,L]

RewriteRule ^notifications/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)$ notifications.php?type=$1&cat=$2 [NC,L]

推荐阅读