I
I
Issue2020-12-13 06:01:32
linux
Issue, 2020-12-13 06:01:32

Why doesn't RewriteRule work on localhost?

When developing a site, I usually use .htaccess with Joomla, it works great on hostings. On localhost did not want to work. "Googled" another .htaccess, it also works on hosting, but it doesn't work for me either:

<Directory "/var/www/html/">
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php
</Directory>


At the address localhost/ - it works without .htaccess. But at the address localhost/test - I get an error:
Not Found
The requested URL was not found on this server.
Apache/2.4.29 (Ubuntu) Server at localhost Port 80

Why doesn't .htaccess work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-12-13
@paulenot

httpd.apache.org/docs/2.4/mod/core.html#directory
The directive <Directory>is only available in server config, virtual host.
If you push it into .htaccess, then instead of the site there will be an error page 500, and an entry in error.log. <Directory not allowed here
If the site opens with such .htaccess, then .htaccess processing is disabled in the AllowOverride settings and these files are simply ignored.
On Ubuntu, VirtualHost configuration files are located in /etc/apache2/sites-available/.
To enable .htaccess, replace AllowOverride Nonewith You AllowOverride All
may also need to enable mod_rewrite
sudo a2enmod rewrite
And don't forget to restart apache
sudo service apache2 restart

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question