Can’t get .htaccess to work on localhost

I am trying to get mod_rewrite to work by using a .htaccess file on my localhost server.

My apache2.conf file contains:

Read More
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

And:

Include mods-enabled/*.load

/etc/apache2/mods-enabled/rewrite.load file contains:

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

The .so file exists.

service apache2 restart shows no warnings/errors

My .htaccess contains:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /process.php?path=$1 [NC,L,QSA]

And it’s located at /var/www/wp/wp-content/plugins/myplugin/

process.php contains print_r($_SERVER);

I am visiting http://localhost/wp/wp-content/plugins/myplugin/randomstring and always getting a 404 error.

I tried changing the .htaccess file to a random string trying to trigger a 500 error to make sure the .htaccess was being “executed”(?), but still getting a 404 not found error.

var_dump(in_array('mod_rewrite', apache_get_modules())); returns true

what am i doing wrong? This always works on my online servers.

Related posts

1 comment

  1. Check if the module is enabled using php_info(). If there is some errors.

    Try the following command.

    sudo a2enmod rewrite
    

    I think if you change (/etc/apache2/sites-available/default) AllowOverride none to AllowOverride All then it will work.

    If still you are getting the error, then do the steps mentioned here.

    The tutorial is bit old, but you can get the module working.

    I hope this helps.

Comments are closed.