The target of the rewrite needs to be the physical internal server location where the content actually resides, not the old URL for that content.
URLs are used out on the web. Files and folders are used inside the server. They are not at all the same thing, merely related by the server configuration.
If the old URL was
and it was served (by way of a rewrite) by the file at
and you want to use a URL like
instead, you now need to:
1. redirect requests for example.com/folder1/folder2/page to www.example.com/page
2. redirect requests for example.com/index.php?param1=folder1¶m2=folder2&pagename=page to www.example.com/page
3. rewrite requests for www.example.com/page to /index.php?param1=folder1¶m2=folder2&pagename=page
Notice that a redirect maps a URL to a URL and a rewrite maps a URL to an internal location.