title: Using mod_rewrite to return 404 for all requests on http
body: <p>I am configuring apache to create a site that will use mod_jk to connect to an app running on tomcat.  </p>
  
  <p>I only want https requests to access my app and I would like to use mod_rewrite to return a 404 for any  http request on port 80.  </p>
  
  <p>Here is my attempt at a VirtualHost configuration </p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
    ServerName admin.app.com
    RewriteEngine On
    RewriteRule ^ [L,R=404]
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:443&gt;
    ServerName admin.app.com
    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/bla.crt
    SSLCertificateKeyFile /etc/apache2/ssl/bla.key
    SSLCACertificateFile /etc/apache2/ssl/bla.ca
    SSLProtocol all
    SSLCipherSuite HIGHT:MEDIUM
  
    JkMount /myapp* 
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Now all is well and good when hitting <a href="https://admin.app.com/myapp" rel="nofollow">https://admin.app.com/myapp</a> - I am able to access my tomcat app confirming that mod_jk and my SSL certificates are working as I expected, however any url request I make with http:// returns 400 bad request, not the 404 that I was expecting.</p>
  
  <p>I added RewriteLog and RewriteLogLevel 3 and got the following output </p>
  
  <pre><code>(2) init rewrite engine with requested uri /
  (3) applying pattern '^' to uri '/'
  (2) rewrite '/' -&gt; '[L,R=404]'
  (2) local path result: [L,R=404]
  (2) init rewrite engine with requested uri /myapp/favicon.ico/
  (3) applying pattern '^' to uri '/myapp/favicon.ico/'
  (2) rewrite '/myapp/favicon.ico/' -&gt; '[L,R=404]'
  (2) local path result: [L,R=404]
  </code></pre>
  
  <p>Which I interpret to mean that 404s should be returned</p>
  
  <p>My question is why am I getting a 400 Bad Request when the log seems to be rewriting my requests correctly to 404s, and furthermore, what is the best practise regarding allowing a site to be accessible only via https.</p>