Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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)"
share|improve this question
    
have you enabled the apache rewrite log and seen what it's generating as output? httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritelog –  EightBitTony Aug 16 '11 at 8:42
    
I added RewriteLog /var/www/rewrite.log to the nibble site virtual host file, the rewrite.log file is empty though, I have made its permissions 777 just in case but all urls I try produce no entries into it. –  Luke Aug 16 '11 at 9:56
    
is the access log for your virtualhost seeing any traffic? –  EightBitTony Aug 16 '11 at 10:01
    
I have pasted from /var/log/apache2/access.log above –  Luke Aug 16 '11 at 10:03
1  
777 is a TERRIBLE PERMISSION SET. Change that right now to 644 for files and 755 for directories and stuff that should be executable. –  Shadur Aug 17 '11 at 10:21
show 9 more comments

2 Answers

up vote 3 down vote accepted
+50

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

share|improve this answer
add comment

Specify AccessFileName directive to use .htaccess file.

AccessFileName .htaccess

Enable the rewrite engine and then restart the service.

sudo a2enmod rewrite 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.