I've .htaccess file using the code:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) ?p=$1  [L] 

however i would like it to convert not just URI string to some get parameter p but additionally other get parameters to p, quite simply:
domain.com/somewhere/somepage.html?foo=2 ---->
domain.com/?p=urlencoded(somewhere/somepage.html?foo=2)
How do i do this?

Use following code inshtaccess file

Options +FollowSymlinks -MultiViews
RewriteEngine on

RewriteCond %{QUERY_STRING} !^p= [NC]
RewriteRule . /?p=%{REQUEST_URI}?%{QUERY_STRING} [L]

Since NE flag isn't provided here so mod_rewrite engine will scribe your original URI before internally redirecting.