title: How do I troubleshoot why my rewrite rules aren't being applied by Apache?
body: <p>I've got a tomcat 6 web app running with Apache httpd as the front end. I'm using mod_proxy and mod_proxy_ajp to forward the requests to tomcat. My server is running Ubuntu. Now I'm trying to use mod_rewrite to remove the leading www, so that my canonical website URL is <code>http://example.com</code> rather than <code>http://www.example.com</code></p>
  <p>I've read a number of tutorials on using mod_rewrite, but I can't get any rewriting to work. I've tried putting the rewrite rule in an <code>.htaccess</code> file (after modifying my <code>/etc/apache/sites-available/default</code> file to set AllowOverride all). I've tried putting the rewrite rule in <code>apache2.conf</code>, <code>httpd.conf</code>, and <code>rewrite.conf</code>. I've tried all of these with rewrite logging turned on. The log file gets created, but Apache has written nothing to it. I thought maybe mod_proxy was somehow preventing the rewrite rules from being used, so I tried disabling that as well...and I still get no rewrite, and nothing to the log.</p>
  <p>At this point I have absolutely no idea what to try next. How do I go about troubleshooting why Apache isn't using my rewrite rules?</p>
  <p>For reference, here are my rewrite directives:</p>
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  
      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
      RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
      RewriteLog &quot;/var/log/apache2/rewrite.log&quot;
      RewriteLogLevel 3
  
  &lt;/IfModule&gt;
  </code></pre>
  <p>the responses below are helpful to my particular case, but probably not as helpful to the community-at-large as answers about how you troubleshoot Apache directives in general. For example, is there a way to enable logging to the point where it would tell me which directives are being applied in which order as the request comes in?</p>
  <p><strong>Edit 2</strong>: I've gotten things to work now. My virtual hosts weren't quite set up right, and I also didn't quite have the rewrite regex right. Here is the final rewrite directives I got to work:</p>
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
          RewriteEngine On
          RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
          RewriteRule ^(.*)$ http://example.com$1 [L,R=301]
  &lt;/IfModule&gt;
  </code></pre>