重写规则问题

发布于 2024-09-08 18:57:11 字数 319 浏览 1 评论 0原文

RewriteRule ^foo-bar-([0-9]+)-([a-z]+)-([a-z-+]+)/$ index.php?a[]=&b=$1&c=$2&d=$3&e=$4&f=$5 [L,NC]

我怎样才能将规则中的最后一个参数设置为不需要,而不添加两行并在第一行中将其删除,然后在第二行中保留......?

因此,规则必须在一行中,但有两个选项可以用于 acees url,例如:

/foo-bar-2-steps/

/foo-bar-2-steps-eq/
RewriteRule ^foo-bar-([0-9]+)-([a-z]+)-([a-z-+]+)/$ index.php?a[]=&b=$1&c=$2&d=$3&e=$4&f=$5 [L,NC]

how could i put the last parameter from rule to not be required without to add two lines and in first one to remove it, then in second to remain..?

so, rule to be in one line but to have two option to acees url like:

/foo-bar-2-steps/

/foo-bar-2-steps-eq/

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

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

发布评论

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

评论(1

心的位置 2024-09-15 18:57:11

以下之一:

  • 使用两个重写规则,每种情况一个 在
  • 可选部分后面加一个问号,如下所示:

foo-bar-([az]+)(-([az]+))?< /code>

这里,第二个参数是可选的。请注意,这会更改您的数字索引,因为您使用了额外的括号。

One of the following:

  • Use two rewrite rules, one for each case
  • Put a question mark after the optional part, like this:

foo-bar-([a-z]+)(-([a-z]+))?

Here, the second parameter is optional. Note that this changes your numerical indexes, since you use extra parenthesis.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文