RewriteEngine On
# registered user files
RewriteRule ^files/(([a-z0-9_]+)/)?([0-9]+)_([a-z0-9]+)/.* getfile.php?action=$2&file_id=$3&file_key=$4 [L,NC,QSA]
RewriteRule ^thumbs/(large|small|square)/([0-9]+)_([a-z0-9]+)/.* getfile.php?action=thumb&size=$1&file_id=$2&file_key=$3 [L,NC,QSA]
RewriteRule ^view/((full)/)?([0-9]+)_([a-z0-9]+)$ view.php?action=$2&file_id=$3&file_key=$4 [L,NC,QSA]
# Public files
RewriteRule ^public/((browse|viewset|manage|slideshow)/?)?(([a-z0-9]+)\_)?([0-9]+)?/?$ public.php?action=$2&upload_key=$4&upload_id=$5 [L,NC,QSA]
RewriteRule ^public/view/((full)/)?([0-9]+)/?$ pview.php?action=$2&file_id=$3 [L,NC,QSA]
RewriteRule ^pfiles/(([a-z0-9_]+)/)?([0-9]+)/.* pfile.php?action=$2&file_id=$3 [L,NC,QSA]
RewriteRule ^pthumbs/(large|small|square)/([0-9]+)/.* pfile.php?action=thumb&size=$1&file_id=$2 [L,NC,QSA]
# User links
RewriteRule ^/*browse/+([a-z0-9_]+)/?(/([0-9]+)_?([a-z0-9]*)(/page([0-9]+))?)?/?$ browse.php?action=browse&username=$1&folder_id=$3&folder_key=$4&page=$6 [L,NC,QSA]
RewriteRule ^/*info/+([a-z0-9_]+)/?$ browse.php?action=info&username=$1 [L,NC,QSA]
RewriteRule ^/*pm/+([a-z0-9_]+)/?$ usercp.php?action=sendpm&username=$1 [L,NC,QSA]
# Rules for making links cleaner.
RewriteRule ^/*(public|folders|usercp|account|myfiles|upload|slideshow|comment|contacts|announcements)/?$ $1.php [L,NC,QSA]
RewriteRule ^/*slideshow/([0-9]+)(_([a-z0-9]+))?$ slideshow.php?folder_id=$1&folder_key=$3 [L,NC,QSA]
RewriteRule ^register/?$ account.php?action=register [L,NC,QSA]
RewriteRule ^login/?$ account.php?action=login [L,NC,QSA]
RewriteRule ^members/?$ browse.php [L,NC,QSA]
RewriteRule ^members/page([0-9]+)/?$ browse.php?page=$1 [L,NC,QSA]
RewriteRule ^members/public/?(page([0-9]+))?/?$ browse.php?public=1&page=$2 [L,NC,QSA]
RewriteRule ^members/info/([0-9]+)$ browse.php?action=info&userid=$1 [L,NC,QSA]
RewriteRule ^members/browse/([0-9]+)/?(/.+)?$ browse.php?action=browse&userid=$1&folder=$2 [L,NC,QSA]
RewriteRule ^contacts/(add|delete|edit)/([a-z0-9_]+)$ contacts.php?action=$1&username=$2&use=username [L,NC,QSA]
# registered user files
RewriteRule ^files/(([a-z0-9_]+)/)?([0-9]+)_([a-z0-9]+)/.* getfile.php?action=$2&file_id=$3&file_key=$4 [L,NC,QSA]
RewriteRule ^thumbs/(large|small|square)/([0-9]+)_([a-z0-9]+)/.* getfile.php?action=thumb&size=$1&file_id=$2&file_key=$3 [L,NC,QSA]
RewriteRule ^view/((full)/)?([0-9]+)_([a-z0-9]+)$ view.php?action=$2&file_id=$3&file_key=$4 [L,NC,QSA]
# Public files
RewriteRule ^public/((browse|viewset|manage|slideshow)/?)?(([a-z0-9]+)\_)?([0-9]+)?/?$ public.php?action=$2&upload_key=$4&upload_id=$5 [L,NC,QSA]
RewriteRule ^public/view/((full)/)?([0-9]+)/?$ pview.php?action=$2&file_id=$3 [L,NC,QSA]
RewriteRule ^pfiles/(([a-z0-9_]+)/)?([0-9]+)/.* pfile.php?action=$2&file_id=$3 [L,NC,QSA]
RewriteRule ^pthumbs/(large|small|square)/([0-9]+)/.* pfile.php?action=thumb&size=$1&file_id=$2 [L,NC,QSA]
# User links
RewriteRule ^/*browse/+([a-z0-9_]+)/?(/([0-9]+)_?([a-z0-9]*)(/page([0-9]+))?)?/?$ browse.php?action=browse&username=$1&folder_id=$3&folder_key=$4&page=$6 [L,NC,QSA]
RewriteRule ^/*info/+([a-z0-9_]+)/?$ browse.php?action=info&username=$1 [L,NC,QSA]
RewriteRule ^/*pm/+([a-z0-9_]+)/?$ usercp.php?action=sendpm&username=$1 [L,NC,QSA]
# Rules for making links cleaner.
RewriteRule ^/*(public|folders|usercp|account|myfiles|upload|slideshow|comment|contacts|announcements)/?$ $1.php [L,NC,QSA]
RewriteRule ^/*slideshow/([0-9]+)(_([a-z0-9]+))?$ slideshow.php?folder_id=$1&folder_key=$3 [L,NC,QSA]
RewriteRule ^register/?$ account.php?action=register [L,NC,QSA]
RewriteRule ^login/?$ account.php?action=login [L,NC,QSA]
RewriteRule ^members/?$ browse.php [L,NC,QSA]
RewriteRule ^members/page([0-9]+)/?$ browse.php?page=$1 [L,NC,QSA]
RewriteRule ^members/public/?(page([0-9]+))?/?$ browse.php?public=1&page=$2 [L,NC,QSA]
RewriteRule ^members/info/([0-9]+)$ browse.php?action=info&userid=$1 [L,NC,QSA]
RewriteRule ^members/browse/([0-9]+)/?(/.+)?$ browse.php?action=browse&userid=$1&folder=$2 [L,NC,QSA]
RewriteRule ^contacts/(add|delete|edit)/([a-z0-9_]+)$ contacts.php?action=$1&username=$2&use=username [L,NC,QSA]