Enable .htaccess on ubuntu

11

I'm using the ubuntu system on my PC and my apache does not seem to recognize htaccess, none since I created a .htaccess for my project only it does not interpret what's 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 I access for example http://localhost/FJU/relatorio it does not display the page I want, it does not send the command and the displayed error 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 have tried using the $ sudo a2enmod rewrite command and edit the / etc / apache2 / sites-available / default directory file to:

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

But nothing worked.

    
asked by anonymous 24.08.2014 / 01:57

1 answer

19

You're on the right path.

mod_rewrite

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

sudo a2enmod rewrite

htaccess

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

Ubuntu 13.04 or lower and Apache 2.2

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

AllowOverride None

By:

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>

Do not forget to restart apache after applying the settings:

sudo service apache2 restart

Sources:

24.08.2014 / 02:27