Forum Moderators: phranque
#add trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^/(.*)$ /$1/
#if its not a folder
RewriteCond %{SCRIPT_FILENAME} !-f
#or a directory
RewriteCond %{SCRIPT_FILENAME} !-d
#put the psuedo directories into querystring
RewriteRule ^/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?page=$1&category=$2&item=$3 [L]
If anyone has the time to answer I'd be very grateful
Also, if you do need to do a file/directory exists check, then only do it once per request - Note how the last three rules now 'share' this check.
# Add missing trailing slash if no period in final URL-path-part
RewriteRule ^/(([^/]+/)*[^./]+)$ http://www.example.com/$1/ [R=301,L]
#
# Skip next 3 rules if final URL-path-part contains a
# period or if URL resolves to existing folder or file
RewriteCond %{REQUEST_URI} ^/([^/]+/)*[^./]+\.[^/]+$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/ - [S=3]
#
# Rewrite pseudo-directories to script path with querystring
RewriteRule ^/([^/]+)/$ /index.php?page=$1 [L]
RewriteRule ^/([^/]+)/([^/]+)/$ /index.php?page=$1&category=$2 [L]
RewriteRule ^/([^/]+)/([^/]+)/([^/]+)/$ /index.php?page=$1&category=$2&item=$3 [L]