开发者

Rewriting rule for category and product page

开发者 https://www.devze.com 2023-01-25 04:37 出处:网络
I want to 开发者_如何学JAVAuse static URLs on my site, so when a user goes to http://www.domain.com/toys/ - he will see the toys category page

I want to 开发者_如何学JAVAuse 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


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]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号