How can a 301 Redirect be used to redirect one domain to another while keeping the original domain in the address field?

A 301 Redirect can be used to redirect one domain to another while keeping the original domain in the address field by using mod_rewrite rules in the .htaccess file. This can be achieved by specifying the original domain in the RewriteCond and using the %{REQUEST_URI} variable to append the path to the new domain in the RewriteRule.

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