Your rules are in the wrong order.
Put all external redirects first, ordered from most-specific to least-specific. Most-specific rules affect one or only a few URLs, as exemplified by your "index.php" canonicalization rule. Least-specific is the catch-all non-canonical domain redirect.
BTW, that rule could do with some improvement. If you don't use any subdomains other than www, then the following is a much more robust solution:
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
It also avoids adding a trailing slash to all requests -- a possible contributor to your declared problem.
Follow your external redirects with all of your internal rewrites, again from most-specific to least-specific.
The variable $2 in your first internal rewrite rule above is undefined; Omit the "&leveltwo=$2" query part, or give "leveltwo=" a hard-coded value.
You can replace internal rewrites two and three with a single rule by making the trailing slash optional:
RewriteRule ^([^/]*)/([^/]*)
/?$ /?levelone=$1&leveltwo=$2 [L]
Only one "RewriteEngine on" is needed. It must precede any other mod_rewrite directives.
One comment on your narrative. mod_rewrite will be far easier to understand if you keep in mind that it either performs a URL-to-URL translation (external redirect), or it does a URL-to-filepath translation (internal rewrite.) Therefore, the statement, "Htaccess calls the php page with the following URL: ..." is incorrect, as .htaccess merely translates a request for the
URL www.example.com/yyy/zzz/ into a request for the
file at "/index.php" with a query string of "levelone=yyy&leveltwo=zzz".
It's much easier to understand what's going on in mod_rewrite if you keep URLs and filepaths as two completely separate and distinct concepts.
One final comment: Adding slashes to 'page' URLs is generally a mistake, although doing so may be required by some CMS packages. URLs with trailing slashes are generally assumed to refer to directory indexes or to index pages in directories (my statement above about URLs versus filepaths notwithstanding). If it is an option and your site is not already well-linked, well-indexed, and well-trafficked, drop the trailing slashes from 'page' URLs instead of adding them.
Jim