title: Rewrite URL using Apache for redirecting root domain
body: <p>I have this scenario where I would like to redirect my domains using the following scenario. Can you please advice if this can be achieved using RewriteRule in Apache?</p>
  
  <p>I would like to redirect any calls made using <a href="http://www.domainname.com/url" rel="nofollow">http://www.domainname.com/url</a> to redirect to <a href="http://domainname.com/url" rel="nofollow">http://domainname.com/url</a>.</p>
  
  <p>I was able to achieve the above using the following rewrite rule</p>
  
  <pre><code># BEGIN WithoutWWW
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^www\.domainname\.com$ [NC]
  RewriteRule ^(.*)$ http://domainname.com/$1 [R=301,L]
  # END WithoutWWW
  </code></pre>
  
  <p>If anyone tries to visit just <a href="http://www.domainname.com" rel="nofollow">http://www.domainname.com</a> or <a href="http://domainname.com" rel="nofollow">http://domainname.com</a>, I would like them to redirect to <a href="http://dname.com" rel="nofollow">http://dname.com</a></p>
  
  <p>How can I achieve this rule using RewriteRule in Apache?
  I'm also using PHP, so a solution using PHP would be valid too.</p>