I'm trying to get a PHP routing library set up. They give this example for a .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

I couldn't get this to work, so I tried enabling mod_rewrite, but it says "Module rewrite already enabled".

Why is it not working properly? Thanks! I'm running Ubuntu Precise 12.04, and apache2.2.22. (Checked for any updates)

EDIT: A couple more details, it's a PuPHPet vagrant build, rewrite should be enabled.

up vote 26 down vote accepted

You need to allow the overwrite.

<Directory "/path/to/document/root/">
  AllowOverride All
  Allow from All
</Directory>
  • 3
    This is unnecessarily permissive. Only AllowOverride is necessary for the configuration in question. Allow from All has nothing to do with the question and may not be appropriate for @randomdev's environment. – Mark Dec 19 '15 at 16:15
  • <Directory "/path/to/document/root/"> I forgot to change /path/to/document/root/ to my project root.Thanks! – Abhishek Mar 16 at 6:38

First of all, set your httpd configuration to this (the path may differ with one another. In my ubuntu it's placed at /etc/apache2/sites-available/default):

DocumentRoot /var/www

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

After that, you should enable mod_rewrite with this command:

sudo a2enmod rewrite

The last one, restart your apache service:

sudo service apache2 restart

To ensure that, you can check it again from phpinfo in Configuration > apache2handler > Loaded Modules there must be written mod_rewrite and it means mod_rewrite is enabled.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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