Apache2 mod_rewrite directive
It's an Apache config file. It isn't going to look pretty. :)

That being said, I don't understand why you have RewriteCond specified for any of these rules. What is that condition preventing? The rewritten URL's are not causing redirect, so it is not clear to me when you would ever run into the condition of having "code" as a query string parameter. 

These conditions really don't make sense for case when you are adding trailing slashes, and if you truly are getting query strings in these trailing slash use cases, you are effectively stripping the query string out of the redirect as you are not using QSA flag.

You should consider using R=301 flag instead of just R for these trailing slash redirect use cases in order to signal to the client that this is permanent location for the resource that is to be used.

I personally find it easier to read through rewrite logic and have that logic to be less error prone if all redirects are handled first in the file, followed by more complex rewrite logic.

Finally, if your app keeps growing in complexity to where you have more of these redirect rules being added, you might consider simply moving to more of a front controller model where you evaluate the URI in PHP and route within your application accordingly.