php - 当我使用多个参数时,无法使用 .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/
解决方案
试试下面的规则,我们用'$'符号来表示我们规则的边界。
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]
推荐阅读
- javascript - HTML,根据这些表中的最宽列设置多个表的列宽
- javascript - 是否有工具可以使用与以前版本的差异来修补生成的文件?
- gekko - 使用 GEKKO 避障问题(未找到解决方案,存在解决方案)
- c++ - 自定义间隔的 SDL2 Vsynced 渲染器和物理 - 是否需要单独的线程?
- jestjs - Jest 中的 globalSetup、setupFiles、setupFilesAfterEnv 和 beforeAll 有什么区别,它们的具体用途是什么?
- python - 我可以在带有 Sphinx autodoc 的 Python 文档字符串中使用 :noindex: 吗?
- java - 同步是否适用于类中的所有方法或仅适用于 1?
- javascript - CodeMirror 多行颜色代码格式无法正常工作
- javascript - 从输入字段中获取占位符数据的总和
- xml - xmlstartlet 如何在节点上方插入行