you could take a look on
where I provided a solution for EL I use to get a proper Itemid.
It' not exact what you want but maybe it helps. Possibly you could create (invisible) menu items for each category (e.g. with alias "class") to get nearly the url you like. But I don't remember how good my adaptions work to find the best matching menu item.
The .htaccess I only use to redirect to the home page as fallback. I hadn't taken the time to understand all the possibilities there.