I have got a VirtualHost that appears something similar to:

<VirtualHost *:80>

  ServerName  domain1.com

  ServerAlias world wide web.domain1.com domain2.com world wide web.domain2.com

</VirtualHost>

When someone visits world wide web.domain1.com/test, they must be rerouted to:

domain1.com/test

When someone visits world wide web.domain2.com/test, they must be rerouted to:

domain2.com/test

My current RewriteRules are missing.

Edit: Some tips about what I have got to date:

# Rewrite world wide web to non-world wide web

RewriteEngine on

RewriteCond % www.%$ [NC]

RewriteRule ^(.*)$ http://%/$1 [L,R=301]

Clearly, this creates an infinite redirect loop.

Your RewriteCond is a little wonky. I am surprised it will anything whatsoever, because it would appear to become attempting to match the host world wide web.domain1.com from the pattern www.world wide web.domain1.com. These directives labored for me personally:

# Redirect world wide web to non-world wide web

RewriteEngine on

RewriteCond % ^www.(.+)$ [NC]

RewriteRule ^(.*)$ http://%1$1 [L,R=301]

No requirement for rewrites.

<VirtualHost *:80>

    ServerName domain1.com

    ServerAlias domain2.com

    ... real vhost configurations ...

</VirtualHost>

<VirtualHost *:80>

    ServerName world wide web.domain1.com

    Redirect permanent / http://domain1.com/

</VirtualHost>

<VirtualHost *:80>

    ServerName world wide web.domain2.com

    Redirect permanent / http://domain2.com/

</VirtualHost>

You could have multiple VirtualHosts inside a configuration file, which means you should improve your config for this:

<VirtualHost *:80>

    ServerName domain1.com

    ServerAlias world wide web.domain1.com

</VirtualHost>

<VirtualHost *:80>

    ServerName domain2.com

    ServerAlias world wide web.domain2.com

</VirtualHost>

You can include another VirtualHost for every domain for you to do.