I want to rewrite domain.com/pagename to /index.php?page=$pagename with this simple rule:
RewriteRule ^(.*)$ index.php?page=$1 [L]
But paradoxically I always get index.php for $1 and not pagename, why is that?
You have an infinite redirect loop, that's why you get an unexpected result (weird you don't get an Internal Server Error, by the way...)
Here is a rule for what you want
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ /index.php?page=$1 [L]
It checks if the url is not a physical folder/file before rewriting it internally. This rule is valid for one-level url only (eg. http://example.com/placeholder and not http://example.com/placeholder/somethingelse)
Try this
http://example.com/pagename => http://example.com/index.php?page=$pagename
RewriteRule ^pagename$ /index.php?page=$pagename&%{QUERY_STRING}