title: Redirect all request from old domain to new domain
body: <p>I am looking to migrate from old domain to new domain.</p>
  
  <p>I have my old domain <code>olddomain.com</code> and new domain <code>newdomain.com</code> pointing to same ip address for now.</p>
  
  <p>I have Apache server inplace to handle requests.</p>
  
  <p>How do I <code>301 redirect</code> all my </p>
  
  <pre><code>olddomain.com/*
  </code></pre>
  
  <p>&amp;</p>
  
  <pre><code>www.olddomain.com/*
  </code></pre>
  
  <p>to </p>
  
  <pre><code>newdomain.com/*
  </code></pre>
  
  <p>Can I get exact regex or configuration that I need to add in <code>htaccess</code>.</p>
  
  <p><strong>My newdomain.com and olddomain.com both are being serverd by same apache from same IP so "/" redirect might lead to cycles? And so was looking for effecient way</strong></p>
  
  <p>I tried </p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
      RewriteCond %{HTTP_HOST} ^localhost$ [OR]
      #  RewriteCond %{HTTP_HOST} ^www.olddomain.com$
      RewriteRule (.*)$ http://comp16/$1 [R=301,L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>And even tried adding in virtual host</p>
  
  <pre><code>RedirectMatch (.*)\.jpg$ http://comp17$1.jpg 
  </code></pre>
  
  <p>But it does not redirect site when i hit localhost in browser to my computer name i.e comp16</p>