Friendly URLs causing havok with pagination

I’m working on a photo gallery that uses “Friendly” URLs, and so far everything is working quite well.

I have a Rewrite rule that makes this:

Look like this:

My problem now is that some albums are pretty huge, so I’d like to add pagination. I wrote something to append ?page=1 to the end of the URL string, but that seems to “break” my setup.

Here are the rewrite rules I have now. Keep in mind that some albums have sub-albums (/album/sub-album/pic), and some just have pics (/album/pic)

RewriteRule gallery/(\\w+)/$ /gallery/index.cfm?album=$1 [NC]
RewriteRule gallery/(\\w+)$ /gallery/index.cfm?album=$1 [NC]

RewriteRule gallery/(\\w+)/(\\d+)$ /gallery/index.cfm?album=$1&photo=$2 [NC]
RewriteRule gallery/(\\w+)/(\\d+)/$ /gallery/index.cfm?album=$1&photo=$2 [NC]

RewriteRule gallery/(\\w+)/(\\w+)$ /gallery/index.cfm?album=$2 [NC]
RewriteRule gallery/(\\w+)/(\\w+)/$ /gallery/index.cfm?album=$2 [NC]

RewriteRule gallery/(\\w+)/(\\w+)/(\\d+)$ /gallery/index.cfm?album=$2&photo=$3 [NC]
RewriteRule gallery/(\\w+)/(\\w+)/(\\d+)/$ /gallery/index.cfm?album=$2&photo=$3 [NC]

This might look horrific to some of you, but I am a COMPLETE novice when it comes to Mod Rewrite.

I’m just not sure how to add an argument for &page=$ to the URL without breaking what’s there now.


Horrific? Close.



DK, thanks for the candid assessment of my pseudocode. I think I’ll read the tutorial linked in your sig, as it looks a bit more basic (notice-oriented) than some of the others I’ve tried to wrap my head around.

Just as a follow-up, I found that tutorial priceless. I had to make some changes to my site, most of which were changing links to remove the trailing slash. I’m used to adding this, because at work, out link checker reports any URLS that don’t end in a slash (or a filename) as a broken link, so it was natural to do this for my website.

Once I got rid of those and added the updated the flags, I was quickly able to get pagination working. So /gallery/bikes?page=2 works a charm. I’ve also cleaned up some of the other rewrite rules I had in place for other pages.

Thanks again for the help.


Horray! (partier) I’m glad that the tutorial helped you, too!

As an aside, the trailing slash SHOULD be used on directories but NEVER on files (because it changes directory level of the request and that affects the relative links). Apache handles directories (with or without) the trailing /'s but it requires Options MultiViews (which serves files in the path whether the file extension is present or not - an ugly feature to get around to I keep MultiViews turned off).