我想改写:
www.domain.com/entry/1
或www.domain.com/entry/1/title
至www.domain.com/entry.php?id=1
www.domain.com/entry/1/title/page/2
至www.domain.com/entry.php?id=1&page=2
www.domain.com/entry/1/title/comment
至www.domain.com/entry.php?id=1&a=comment
我在.htaccess文件中有以下内容
RewriteRule ^entry/(([0-9]+))(?:/([^/]*))?/?$ ./entry.php?id=$1
RewriteRule ^entry/([0-9]+)/([^/]+)/page/([0-9]+)$ ./entry.php?id=$1&page=$3
RewriteRule ^entry/([0-9]+)/([^/]+)/([^/]+)$ ./entry.php?id=$1&a=$3
它在工作。我也尝试将订单反转为:
RewriteRule ^entry/(([0-9]+))(?:/([^/]*))?/?$ ./entry.php?id=$1
RewriteRule ^entry/([0-9]+)/([^/]+)/([^/]+)$ ./entry.php?id=$1&a=$3
RewriteRule ^entry/([0-9]+)/([^/]+)/page/([0-9]+)$ ./entry.php?id=$1&page=$3
它也在工作。如何执行.htaccess文件中的行?上面哪个版本更正确?谢谢!
答案 0 :(得分:0)
没关系。但是一定要在每个RewriteRule行的末尾添加[L]
,以便Apache在成功应用规则后停止,并且不会无休止地循环。
This is also a very useful tool用于测试RewriteRules以及它们是否正常工作。