开发者

2 url rewrite rule for 1 dynamic page

I have a dynamic page called show.php. The page is dynamic and the url may be either show.php?name=john-doe or show.php?category=student.

I'm trying to create a rewrite rule that turns the url into /show/john-doe.html for names or /show/student.html for category.

This is what I have in my .htaccess so far.

RewriteRule ^show/([^/]*)\.html$ show.php?name=$1 [L]
RewriteRule ^show/([^/]*)\.html$ show.php?category=$1 [L]

Curr开发者_开发技巧ently, only the name rule works but the category rule doesn't. What's wrong?


The problem is that you are sending all show/xxx.html to the same URL (the first one). Since both rewrite rules are using exactly the same parameter only the first one will work.

You could solve this in two different ways.

Either you use show.php?id=xxx and accept both name and category in your PHP and detirmine there what page to show.

Or you use two different types of urls in your rewrite to get show/category/student.html and show/student/john-doe.html like so:

RewriteRule ^show/student/([^/]*)\.html$ show.php?name=$1 [L]
RewriteRule ^show/category/([^/]*)\.html$ show.php?category=$1 [L]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜