title: Why is Apache Permanent Redirect removing the slash between the domain and the path?
body: <p>I'm using Apache 2.4, and I set up two virtual directories.  One requires SSL, and the other one redirects to it.</p>
  
  <p>If a user attempts to visit <code>https://www.derp.com/derp</code> without /derp existing, they correctly get a 404.  But when a user visits <code>http://www.derp.com/derp</code>, Apache incorrectly redirects the user to <code>https://www.derp.comderp</code>, removing the slash between the path and the domain name.</p>
  
  <p>I have no idea what would be causing this.</p>
  
  <p>The following is the setup of my Virtual Host.</p>
  
  <pre><code>&lt;VirtualHost *:443&gt;
      ServerAdmin derp@derp.com
      ServerName www.derp.com
      ServerAlias derp.com
      DocumentRoot "C:\Users\derp\Documents\Web Projects\derp"
      SSLEngine on
      SSLCertificateFile "C:\Apache24\certs\cert.cer"
      SSLCertificateKeyFile "C:\Apache24\certs\key.key"
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost *:80&gt;
      ServerAdmin derp@derp.com
      ServerName www.derp.com
      ServerAlias derp.com
      Redirect permanent / https://www.derp.com/
  &lt;/VirtualHost&gt;
  
  &lt;Directory "C:\Users\derp\Documents\Web Projects\derp"&gt;
      Options Indexes FollowSymLinks Includes ExecCGI
      AllowOverride All
      Require all granted
      SSLRequireSSL
  &lt;/Directory&gt;
  </code></pre>
  
  <p>Why would Apache be behaving this way?</p>
  
  <p>Bonus Question: Should redirects be handled in my virtual host definition, or should it be handled in the .htaccess file in the web site's physical directory?</p>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>I'm starting a Laravel project, and by default the public folder does contain a .htaccess file, so here's that guy:</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      Options -MultiViews
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^ index.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>Edit Two:</strong></p>
  
  <p>I tried:    </p>
  
  <ul>
  <li>adding a slash at the end of the DirectoryRoot path</li>
  <li>replacing the backslashes with forward slashes in the DirectoryRoot path</li>
  <li>replacing the backslashes with double backslashes in the DirectoryRoot path  </li>
  </ul>
  
  <p>I also removed the .htaccess file from the directory completely.</p>
  
  <p>It redirects correctly when you go from <code>http://www.derp.com</code> to <code>https://www.derp.com</code>.  It's just when you specify a path and attempt https that it removes the slash between the domain and the path.</p>
  
  <hr>
  
  <p><strong>Edit Three:</strong></p>
  
  <p>I also attempted the following suggestion:</p>
  
  <blockquote>
  <pre><code>Redirect permanent / https://www.derp.com/
  
  Try
  
  RedirectMatch permanent /(.*) https://www.derp.com/$1
  
  or
  
  RedirectMatch permanent (.*) https://www.derp.com/$1
  </code></pre>
  </blockquote>
  
  <p>... and instead of redirecting to <a href="https://www.derp.comderp">https://www.derp.comderp</a>, it instead does not redirect, attempts and gives a 404 for <a href="http://www.derp.com/derp">http://www.derp.com/derp</a>, but using Apache's 404, instead of throwing a Not Found Exception, as Laravel does without configuration.</p>
  
  <hr>
  
  <p><strong>Edit Four:</strong>  </p>
  
  <p>I have also tried:</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      Options -MultiViews
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.php$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>In the .htaccess file and the behavior did not change at all.</p>