6

My .htaccess file doesn't work on my Ubuntu 14.04 with Apache 2.
This is my file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?pg=$1

How do i solve my problem?

  • This may help someone else [Link](http://stackoverflow.com/questions/24675882/htaccess-not-working-on-my-ubuntu-14-04-distribution/36259341#36259341) – Muhammad Shahzad Mar 28 '16 at 09:21

4 Answers4

17

From your information I can only guess ("doesn't work" isn't very specific).
Most probably you did not enable mod_rewrite. Type in:

a2enmod rewrite

and restart Apache after:

service apache2 restart

Horen
  • 11,184
  • 11
  • 71
  • 113
9

First Step Open file as

sudo vim /etc/apache2/apache2.conf

Second Step remove comment sign (#) if you find it before this line ( line number 187 approx.) AccessFileName .htaccess

Third Step Then find the line where there is Options Indexes FollowSymLinks AllowOverride None Require all granted

replace "None" with "All"

AllowOverride All

.htaccess it's works!!

Donot Don't
  • 609
  • 7
  • 12
5

If its Ubuntu LAMP fresh installation, you can followup with these steps. It just the sum-up from the above points:

Step 1:

If you have sudo access for your Ubuntu server open the apache2.conf file

root@etc/apache2$ vi apache2.conf

Step 2:

Change Directory /var/www/ from AllowOverride None to AllowOverride All

share the file permission level for .htaccess from denied to granted

Step 3:

Change the same settings in root@etc/apache2/sites-enabled/$ vi 000-default.conf file

Step 4:

Run a2enmod rewrite

This step is really important. It prompts you to restart the server.

Step 5: Restart the server

service apache2 restart  

if the above step fails run

 sudo /etc/init.d/apache2 restart
kishorekumaru
  • 1,500
  • 2
  • 19
  • 33
  • 1
    This is the best answer because it's the most comprehensive. I tried just editing the `AllowOverride None` but what was additionally needed was editing the `.htaccess` permission to granted – Hamman Samuel Nov 13 '17 at 06:57
2

If you using latest version on apache2 , you need to add the following lines in /etc/apache2/sites-available/000-default.conf

You need to add following inside this tag

Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all

after that run "service apache2 restart"