Let me have demands to http://example.com/controller rerouted to http://example.com/index.php/controller without altering the url, which is what my .htaccess file appears like:

# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]

  RewriteBase /
  RewriteCond %{HTTP_HOST} ^www.example.com [NC]
  RewriteRule ^(.*)$ http://example.com/$1 [R=301] 
</IfModule>

Regrettably, this does not work. All demands to http://example.com/controller get routed towards the home controller, and also the url does not change. And all sorts of demands to http://www.example.com/controller get routed to http://example.com/index.php/controller and also the url DOES alternation in the address bar.

Any idea what I am missing or doing wrong?

Put individuals rules that create an exterior redirect before individuals that create an interior redirect. So:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} =www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]