title: Remove index.php from Laravel 4 URL and Rewrite www to non-www
body: <p>I have tried several ways to remove index.php from my URL (<a href="http://www.example.com/index.php/login" rel="nofollow">http://www.example.com/index.php/login</a>), as well as redirecting www to the non-www URL.</p>
  
  <p>Here is my default Apache VirtualHost file:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
          ServerAdmin webmaster@example.com
          ServerName example.com
          ServerAlias www.example.com
  
          DocumentRoot /var/www/public/
          &lt;Directory /&gt;
                  Options FollowSymLinks
                  AllowOverride All
          &lt;/Directory&gt;
          &lt;Directory /var/www/public/&gt;
                  Options Indexes FollowSymLinks MultiViews
                  AllowOverride All
                  Order allow,deny
                  allow from all
          &lt;/Directory&gt;
  
          ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
          &lt;Directory "/usr/lib/cgi-bin"&gt;
                  AllowOverride None
                  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                  Order allow,deny
                  Allow from all
          &lt;/Directory&gt;
  
          ErrorLog ${APACHE_LOG_DIR}/error.log
  
          # Possible values include: debug, info, notice, warn, error, crit,
          # alert, emerg.
          LogLevel warn
  
          CustomLog ${APACHE_LOG_DIR}/access.log combined
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Now I have added the following in to this file:</p>
  
  <pre><code>Redirect 301 / http://example.com
  </code></pre>
  
  <p>But this has not worked, I just get a redirect loop message. I also have the following .htaccess:</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>
  
  <p>To which I've added:</p>
  
  <pre><code>RewriteBase /
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  </code></pre>
  
  <p>But this does not work either.</p>
  
  <p>The other issue is that for all of my routes I have to include index.php, like <a href="http://example.com/index.php/test" rel="nofollow">http://example.com/index.php/test</a></p>
  
  <p>It's as if my .htaccess file is being ignored.</p>
  
  <p>The server is a DigitalOcean Droplet running Ubuntu 13.04 x64. It has PHP 5.4.9 and Apache 2.2.22.</p>
  
  <p>Any help would be very much appreciated. Thanks.</p>