类别和产品页面的重写规则

发布于 2024-10-02 04:21:44 字数 625 浏览 0 评论 0原文

我想在我的网站上使用静态 URL,因此当用户访问

http://www.domain.com/ 时,他将看到玩具类别页面

时玩具/ -当他访问

http:// www.domain.com/toys/playing-cards - 他将看到产品页面

我在使用以下重写规则时遇到了一些问题:

RewriteRule ^item/(toys|clothes)/(.*)/?$ showPRODUCT.php?id=$2 [NC,L]
RewriteRule ^item/(toys|clothes)/?$ showCATEGORY.php?product=$1 [NC,L]

因为第一条规则“捕获”了类别 URL (http://www.domain.com/toys/playing-cards)。 domain.com/toys/)以及产品(如果我切换订单,反之亦然)。

有什么想法吗?

谢谢!!

大卫

I want to use static URLs on my site, so when a user goes to

http://www.domain.com/toys/ - he will see the toys category page

and when he goes to

http://www.domain.com/toys/playing-cards - he will see the product page

I am having some trouble with the following rewrite rule:

RewriteRule ^item/(toys|clothes)/(.*)/?$ showPRODUCT.php?id=$2 [NC,L]
RewriteRule ^item/(toys|clothes)/?$ showCATEGORY.php?product=$1 [NC,L]

because the first rule "catches" the category URL (http://www.domain.com/toys/) in addition to the product (and vice versa if I switch the order).

Any ideas?

Thanks!!

David

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

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

发布评论

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

评论(1

猫烠⑼条掵仅有一顆心 2024-10-09 04:21:44
RewriteRule ^item/(toys|clothes)/(.*)/?$ showPRODUCT.php?id=$2 [NC,L]
RewriteRule ^item/(toys|clothes)/?$ showCATEGORY.php?product=$1 [NC,L]

假设开头的“^item”应该在那里......

您需要的是将 * 中继器更改为 + 中继器,这样它就不会与类别匹配。同样,如果找到第一个重写规则,L 标志应该阻止它继续执行另一个重写规则:

RewriteRule ^item/(toys|clothes)/(.+)/?$ showPRODUCT.php?id=$2 [NC,L]
RewriteRule ^item/(toys|clothes)/?$ showCATEGORY.php?product=$1 [NC,L]
RewriteRule ^item/(toys|clothes)/(.*)/?$ showPRODUCT.php?id=$2 [NC,L]
RewriteRule ^item/(toys|clothes)/?$ showCATEGORY.php?product=$1 [NC,L]

Assuming the "^item" at the beginning is supposed to be there...

What you need is to change the * repeater to a + repeater, that way it won't match the category. Likewise, the L flag should stop it from continuing with the other rewriterule if it finds the first one:

RewriteRule ^item/(toys|clothes)/(.+)/?$ showPRODUCT.php?id=$2 [NC,L]
RewriteRule ^item/(toys|clothes)/?$ showCATEGORY.php?product=$1 [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文