It is possible to do that with Apache’s mod_rewrite module like this:
RewriteRule ^/([^/]+/[^/]+)/([^/]+)(/.+)?$ /$1$3?p[]=$2 [N,QSA]
RewriteRule ^/([^/]+)/([^/]+)$ /index.php?c=$1&m=$2 [L,QSA]
But it would definitely be easier to do that with PHP:
$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$segments = explode('/', trim($_SERVER['REQUEST_URI_PATH'], '/'));
if (count($segments) >= 2) {
$_GET['class'] = array_shift($segments);
$_GET['m'] = array_shift($segments);
$_GET['p'] = $segments;
} else {
// error
}
Then you just need one single rule to rewrite the requests:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php$ index.php [L]