bahamut100
bahamut100

Reputation: 1837

How to add a correct rule for page rewriting in .htaccess?

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)

Upvotes: 1

Views: 55

Answers (2)

TobiX
TobiX

Reputation: 944

Are you using both rules or just one?

If you are using both rules in this order:

RewriteRule ^famille/([^/]*)-([^-]*)-([^-]*)\.html$ /fond=famille&id_rubrique=$1&page=$3 [L]
RewriteRule ^famille/([^/]*)-([^-]*)\.html$ /fond=famille&id_rubrique=$1 [L]

then the first group is not exclusive enough. The greedy match will match the first -. Try this:

RewriteRule ^famille/([^-/]*)-([^-]*)-([^-]*)\.html$ /fond=famille&id_rubrique=$1&page=$3 [L]
RewriteRule ^famille/([^-/]*)-([^-]*)\.html$ /fond=famille&id_rubrique=$1 [L]

Or maybe just swap the rules?

PS: As per http://www.w3.org/Provider/Style/URI you might want to leave out the .html...

Upvotes: 1

Nikoloff
Nikoloff

Reputation: 4160

The hyphen before the page number is your problem. Make it optional, try this:

RewriteRule ^famille/([^/]*)-([^-]*)-?([^-]*)\.html$ /?fond=famille&id_rubrique=$1&page=$3 [L]

Upvotes: 1

Related Questions