我是否缺少旗帜或其他东西?需要 RewriteRule 提示

发布于 2024-09-05 22:57:21 字数 292 浏览 3 评论 0原文

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)$ index.php?p=$1&l=$2
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ index.php?p=$1&l=$2

如果我执行 site.com/param_one/param_two/ ,则效果很好,但当我省略 param_two 时,会返回 404。我是使用 htaccess 路由请求的新手,有简单的快速修复吗?

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)$ index.php?p=$1&l=$2
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ index.php?p=$1&l=$2

this works fine if I do site.com/param_one/param_two/, but returns a 404 when I omit param_two. I'm a newbie to routing requests with htaccess, is there a simple quick fix?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一江春梦 2024-09-12 22:57:21

量词+表示一次或多次重复。但 /param_one/ 需要零次或多次重复。因此,请尝试使用 * 量词来进行零次或多次重复:

RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]*)$ index.php?p=$1&l=$2

The quantifier + means one or more repetitions. But /param_one/ would require zero or more repetitions. So try the * quantifier to have zero or more repetitions:

RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]*)$ index.php?p=$1&l=$2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文