mod_rewrite voodoo
Recently i desiced to makeover my image gallery to nice URL. Previous url looked like:
thumbnails.php?album=$2
displayimage.php?album=$2&cat=$3&pos=$5
displayimage.php?pos=-$2
thumbnails.php?album=$2&cat=$3
and so on, after applied mod_rewrite we got:
/album/motosport,20.html
/album/motosport,20/img/cma-m-039-1977-first-monaco-victory-for-checkter,5.html
/img/1135921656-i-3623-full,50659.html
where /album/ main part motosport album name, for SEO who needs it and category ID. mod_rewrite rules looks like:
RewriteRule ^album/(.*),([a-z0-9]*)/category/([0-9-]*)/img/(.*),([0-9-]*)(.html)?$ displayimage.php?album=$2&cat=$3&pos=$5
RewriteRule ^album/(.*),([a-z0-9]*)/img/(.*),([0-9-]*)(.html)?$ displayimage.php?album=$2&pos=$4
RewriteRule ^album/(.*),([a-z0-9]*).html$ thumbnails.php?album=$2
RewriteRule ^album/(.*),([a-z0-9]*)/page/([0-9]*)(.html)?$ thumbnails.php?album=$2&page=$3
RewriteRule ^album/(.*),([a-z0-9]*)/category/([a-z0-9-]*)/page/([0-9]*)(.html)?$ thumbnails.php?album=$2&cat=$3&page=$4
RewriteRule ^album/([a-z0-9]*)/sort/([a-z]*)(.html)?$ thumbnails.php?album=$1&sort=$2
RewriteRule ^album/([a-z0-9]*)/page/([0-9]*)/sort/([a-z]*)(.html)?$ thumbnails.php?album=$1&page=$2&sort=$3
RewriteRule ^category/(.*),([a-z0-9]*).html$ index.php?cat=$2
RewriteRule ^img/(.*),([0-9-]*)(.html)?$ displayimage.php?pos=-$2
RewriteRule ^album/(.*),([a-z0-9]*)/category/([0-9-]*).html?$ thumbnails.php?album=$2&cat=$3
Live example:
http://animeonly.org