If for the last three years your web application has been running under the domain myapp.com but now the boss has decided that it should rather be running under myawesomeapp.com, here is but one method that can help ease your pain in changing the domain of your site.
For this to work, we are assuming that you are running an Apache webserver which has the mod_alias module activated.
The first step would be to create a new virtualhost for the new domain (myawesomeapp.com) under the sites-available apache2 directory and enable it using the handy a2ensite script (if you are running Ubuntu Linux).
Next you would open up your existing site entry for myapp.com and change its contents as follows:
RedirectMatch 301 ^(.*)$ http://myawesomeapp.com
Save your changes and run the following in order to reload Apache’s configuration:
sudo /etc/init.d/apache2 reload
Breaking down what you’ve just done, basically you’ve instructed that for every request coming in to myapp.com, the server should redirect (with a permanent marker) to the new myawesomeapp.com domain but with the rest of the request string intact.
What the documentation tells us: This directive is equivalent to Redirect, but makes use of regular expressions, instead of simple prefix matching. The supplied regular expression is matched against the URL-path, and if it matches, the server will substitute any parenthesized matches into the given string and use it as a filename.