htaccess中的友好URL

I have a problem with friendly url in .htaccess. I need something like this

http://example.com/cnt1/cmp1/act1/id,1/cid,2/sid,3/etc..
http://example.com/index.php?controller=cnt1&component=cmp1&action=act1&data=id,1/cid,2/sid,3/etc..

and

http://example.com/cnt1/cmp1/act1
http://example.com/index.php?controller=cnt1&component=cmp1&action=act1

and

http://example.com/cnt1/cmp1
http://example.com/index.php?controller=cnt1&component=cmp1

and

http://example.com/cnt1
http://example.com/index.php?controller=cnt1

and

http://example.com/
http://example.com/index.php

My .htaccess file:

Options +FollowSymLinks
RewriteEngine on

RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|ico|txt|pdf|xml|zip)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-l
RewriteRule ^([,a-zA-Z0-9_-]*)/?([a-zA-Z0-9_-]*)?/?([a-zA-Z0-9_-]*)?/?([/\.,a-zA-Z0-9_-]*)$ index.php?controller=$1&component=$2&action=$3&data=$4 [NC,L]

ErrorDocument 404 /index.php?controller=error404 

but something is wrong, for example http://example.com/& or http://example.com/< make error Not Found. Can someone help me?

I think you'll have an easy time by using a more simple URL Rewrite rule and parse your url in PHP.

RewriteRule    ^(.*)$    /index.php?query=$1    [END,QSA]

And in your PHP something like

// Parse Query
$default = [
    "defaultController",
    "defaultComponent",
    "defaultAction",
];
$query = explode('/', $_GET['query']);
$temp = array_slice($query, 3);
$query = array_merge($default, array_slice($query, 0, 3));

// Parse Data
if(!empty($temp)) {
    $data = [];
    $m = count($temp);
    for($i=0;$i<$m;++$i) {
        list($k,$v) = explode(',', $temp[$i]);
        $data[$k] = $v;
    }
}
else $data = null;

// Some testing
if(controller_exists($query[0]))
     $controller = $query[0]();
else throw new Exception('Controller not found: '.$query[0]);