Enable . htaccess in Ubuntu

Asked

Viewed 28,571 times

11

I’m using the Ubuntu system on my PC and my apache doesn’t seem to recognize htaccess, none, because I created one. htaccess to my project only that it does not interpret what is in the content. The content is as follows:

.htaccess

RewriteEngine ON

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteBase /FJU/

RewriteRule ^visualizar/([a-z]+)/([0-9]+)$ pages/visualizar.php?p=$1&id=$2
RewriteRule ^(.*)$ index.php?page=$1

Unfortunately when access for example http://localhost/FJU/relatorio it does not display the page I want, does not send the command and the error shown is:

Not Found

The requested URL /FJU/report was not found on this server.

Apache/2.4.7 (Ubuntu) Server at localhost Port 80

I tried enabled using command $ sudo a2enmod rewrite and edit the directory file /etc/apache2/sites-available/default for:

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

But nothing helped at all.

1 answer

19


You’re on the right track.

mod_rewrite

You need to enable the mod_rewrite (it may be that it is already enabled, but it is good to check):

sudo a2enmod rewrite

htaccess

The default file path varies depending on your version of Ubuntu and Apache.

Ubuntu 13.04 or less and Apache 2.2

Edit the file /etc/apache2/sites-available/default and change the line

AllowOverride None

For:

AllowOverride All 

Ubuntu 13.10 or higher and Apache 2.4

Edit the file /etc/apache2/sites-available/000-default.conf and look for the line DocumentRoot /var/www/html.

Add the rule to the directory:

<Directory "/var/www/html">
    AllowOverride All
</Directory>

Don’t forget to restart apache after applying the settings:

sudo service apache2 restart

Sources:

  • 3

    This post was of great help, it worked for me very well, thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.