Apache – Localhost .htaccess not working on Ubuntu

.htaccessapache-httpd

I have been trying to get my .htaccess file to work on my localhost. I know that the file works because it is on my server and works. However it doesn't seem to be working locally.

I have followed the tutorials I could find to set overrides to all, below is my /etc/apache2/sites-available/default file start:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

This is the code in the same directory for my nibble site:

<VirtualHost *:80>
    ServerName nibble.local
    DocumentRoot /var/www/nibble_framework/web/
    <Directory /var/www/nibble_framework/web/>
        AllowOverride All
        Options Indexes FollowSymLinks MultiViews
        Allow from All
    </Directory>
    RewriteLog /var/www/rewrite.log
    ErrorLog /var/log/apache2/error.log
</VirtualHost>

I have enabled this site using a2ensite and restarted apache. I have also added the site to my hosts file:

  127.0.0.1  nibble.local

I have enabled mod rewrite using a2enmod and restarted/reloaded apache multiple times.

  $ a2enmod rewrite 
  Module rewrite already enabled

My .htaccess file is in /var/www/nibble_framework/web/.htaccess and has the following code:

  Options +FollowSymLinks +ExecCGI

  <IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([^/]*)/?.*$ - [E=FILE:%{DOCUMENT_ROOT}/$1.php]

  RewriteCond %{ENV:FILE} !^$
  RewriteCond %{ENV:FILE} -f
  RewriteRule ^([^/]*)/?(.*)$ $1.php?url=$2 [QSA,L]

  RewriteCond %{ENV:FILE} !^$
  RewriteCond %{ENV:FILE} !-f
  RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
  </IfModule>

When I do a print_r($_REQUEST), it is allways an empty array even when the url is poplulated by a long string.

Does anyone have any idea why this might be failing?

Edit:

apache2 access log:

~$ tail -f /var/log/apache2/access.log
::1 - - [16/Aug/2011:07:32:39 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:39 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:39 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"

Best Answer

I suspect your VirtualHost is not getting processed correctly, which would then not set AllowOverride for the get requests. First your /etc/hosts file should look like this..

127.0.0.1   localhost   localhost.localdomain
127.0.1.1   nibble.local

Second, You must have that interface set for namebased vhosts. You did not specify if you have it currently set. Usually its set in the main apache config, I'm guessing ubuntu/debian has that file located /etc/apache2/apache2.conf. Make sure this line is set somewhere in that file,

NameVirtualHost *:80

Once you make these changes, restart apache

sudo /etc/init.d/apache2 restart

Noe test it out, remember you only set that hosts entry locally. So as is this will only work correctly when requested from localhost. If you get stuck, or it doesn't work, post the relevant lines from /var/log/apache2/error.log

Related Question