I tried replacing the existing rewrite rule in .htaccess with this and surprisingly it worked.
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !domain.www/
RewriteRule (.*) /domain.www/$1 [L]