How to make will_paginate generated URL search engine friendly

I m using will_paginate plugin to do the pagination. And I find that the generated URL is like the following format:

http://localhost:3000/site?page=2 http://localhost:3000/site?page=3 ......

how can I let it generate URLs like the following format:(or any other formats which is search engine friendly).

http://localhost:3000/site/page/2 http://localhost:3000/site/page/4

appreciate for your help.

this is how I have it working. i's not necessarily the best way. I'm a newbie.

in routes.rb, after map.resources :posts

# anything like /2 (just a page#) should go to my default controller posts

  map.connect ':page',   :action => 'index',   :controller => 'posts',   :requirements => { :page => /\d+/},   :page => nil

# anything like /posts/tags/rails/2 should go to the appropriate controller and action

  map.connect ':controller/:action/:id/:page',   :requirements => { :page => /\d+/}

Note: there's no page => nil here. page must be present to trigger this rule, otherwise it thinks something like /posts/johnny/2 is asking for action johnny with id 2.

# anything like /posts/johnny/2 should is a show action. i.e., show page 2 of johnny's posts.

  map.connect ':controller/:id/:page',   :requirements => { :page => /\d+/},   :action => 'show',   :page => nil

Note: here the page CAN be nil, so it'll generate the shortest URL, i.e., /posts/johnny instead of /posts/johnny/1

these are RESTful routes I'm using, which you can modify to suit.

sorry, I just found a problem with my scheme. it cannot handle


(action index, page 2)

when controller is something other than my default controller. In fact I don't think there's a way to distinguish between

/controller/page and /controller/id unless your id has some unique pattern other than \d+

I'll let someone more knowledgable chime in :slight_smile:

Thanks for your reply :slight_smile: