I have a database of cartoons and although I've got 1000's of cartoons, Google only has a handful of pages indexed due to the query strings in my URLs. So I'm taking the plunge and using the .htaccess rewrite rule to convert all my dynamic URLs to static ones (or technically speaking, the other way around). My plan was to display the categories in the URL leading down to the cartoon. For example, for cartoon category "Forager", the URL would be:
cartoons.sev.com.au/Sev-Space/Sev-Trek/Forager/
Then for a Forager cartoon of number s663 (each cartoon number takes the form of a letter followed by a number), the URL would be:
cartoons.sev.com.au/Sev-Space/Sev-Trek/Forager/s663
To do this, I've used two rewrite rules - one that rewrites any URL ending with a word of the form "s454" (eg - letter followed by numbers). The other rule rewrites anything ending with a trailing slash, assuming it's a category page, then retrieves the two last categories in the URL. I then run a query to the database to find the category number:
ErrorDocument 404 /error.php
RewriteEngine on
RewriteRule ^(.*)/([fghprst]s?[0-9]+)/?$ /archivepage.php?cartoonid=$2 [L]
RewriteRule ([a-zA-Z\-]*)/?([a-zA-Z\-]*)/$ /category.php?Category=$2&ParentCategory=$1 [L]
My question - my regexs seem a bit clunky (I'm still trying to get the hang of them) and I couldnt' find a way to make them work if someone neglected to type a trailing slash on a category URL. I was just wondering if someone wiser than I might see a better way I could structure my rewrite rules to make it a little more robust.