title: Laravel in subfolder on webhost
body: <p>I have a webapp written in Laravel that needs to run in a folder on a web host.
  The app will have to be accessible via <code>hostname.com/webhit/</code>. This will point to the app's home page.</p>
  
  <p>I only have one route:</p>
  
  <pre><code>Route::controller('/', 'HomeController');
  </code></pre>
  
  <p>HomeController's getIndex needs to serve the home page. <strong>This works.</strong></p>
  
  <p>However, as soon as I want to go to something like <code>hostname.com/webhit/login</code>, I get a 404 from Apache.</p>
  
  <p>Obviously, <code>.htaccess</code> is not working properly. I need it to, essentially, turn URLs that look like <code>hostname.com/webhit/login</code> into <code>hostname.com/webhit/index.php/login</code>.</p>
  
  <p>I have a <code>.htaccess</code> file in <code>www/webhit</code> (where <code>index.php</code> is located) that looks like this:</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      &lt;IfModule mod_negotiation.c&gt;
              Options -MultiViews
          &lt;/IfModule&gt;
  
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ webhit/index.php/$1 [L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>I am not very familiar with <code>.htaccess</code> file syntax, but I believe it's doing something wrong.</p>
  
  <h2>Edit:</h2>
  
  <p>I did it. My <code>.htaccess</code> was wrong (it actually causes a redirect loop), but the issue was that it wasn't even being parsed by Apache (hence the 404 instead of a 500 due to >10 redirects in a request). I did the following steps in order to get everything to work:</p>
  
  <ol>
  <li>Enable <code>mod_rewrite</code> and restart Apache (plenty of docs out there on how to do this)</li>
  <li>But wait, there's more! By default, Apache on Ubuntu prevents URL rewrites. <a href="https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles" rel="nofollow">See this site</a>. Most importantly, the following fragment from the URL above is very important: "By <strong>default</strong>, Ubuntu's Apache will <strong>ignore</strong> the directives in your .htaccess files." You will need to actually enable rewrites by editing <code>\etc\apache2\sites-available\default</code> and setting AllowOverride to all (see link above for more details).</li>
  <li>Reload the configuration (or just restart apache).</li>
  <li>Make sure you're using the correct <code>.htaccess</code>. My original version actually has a redirect loop in it. See the selected response for the correct version.</li>
  </ol>
  
  <p>After this, I got it to work. I hope it helps future programmers having a similar issue!</p>