如何在.htaccess中添加正确的页面重写规则?
我正在尝试在我的网站上建立分页系统。
之前,我有它:
RewriteRule ^famille/([^/]*)-([^-]*)\.html$ /?fond=famille&id_rubrique=$1 [L]
我可以像这样访问我的页面:
http://blabla.net /famille/131-articles_de_cave.html
所以,现在我为分页添加一条规则:
RewriteRule ^famille/([^/]*)-([^-]*)-([^-]*)\.html$ /?fond=famille&id_rubrique=$1&page=$3 [L]
如果继续:
http://blabla.net/famille/131-articles_de_cave-2.html(对于第二页)它有效。
但如果我在第一页,我会收到 404 错误:
http://blabla.net/famille /131-articles_de_cave.html
如何解决这个问题? (我需要在第一页访问,不写页码)
I'm trying to do a paginate system on my website.
Before, I had it :
RewriteRule ^famille/([^/]*)-([^-]*)\.html$ /?fond=famille&id_rubrique=$1 [L]
And I could get to my page like this :
http://blabla.net/famille/131-articles_de_cave.html
So, now I add a rule for the paginate :
RewriteRule ^famille/([^/]*)-([^-]*)-([^-]*)\.html$ /?fond=famille&id_rubrique=$1&page=$3 [L]
If a go on :
http://blabla.net/famille/131-articles_de_cave-2.html (for the page two) it works.
But if I am on the fist page, I get 404 error :
http://blabla.net/famille/131-articles_de_cave.html
How fix this problem ? (I need to access on the first page without write the page number)
您使用这两种规则还是只使用一种规则?
如果您按以下顺序使用这两个规则:
那么第一组的排他性不够。贪婪匹配将匹配第一个
-
。试试这个:或者只是交换规则?
PS:根据 http://www.w3.org/Provider/Style/URI您可能想省略
.html
...Are you using both rules or just one?
If you are using both rules in this order:
then the first group is not exclusive enough. The greedy match will match the first
-
. Try this:Or maybe just swap the rules?
PS: As per http://www.w3.org/Provider/Style/URI you might want to leave out the
.html
...