.htaccess is not working on Ubuntu 16.04.2 LTS

13,875

Solution 1

I was facing same problem, here is solution for ubuntu and apache

First enable module rewrite:

sudo a2enmod rewrite 

And restart apache

sudo systemctl restart apache2

Now edit for directory level

sudo vim /etc/apache2/sites-enabled/000-default.conf

add these lines at end

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

and restart apache again.

sudo service apache2 restart

Solution 2

I found this example that should do the trick:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

Source:

https://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess

https://stackoverflow.com/questions/1992183/how-to-hide-the-html-extension-with-apache-mod-rewrite

Solution 3

Translation adapted from Google Translate

Greetings I had the same problem in a VPS that I contracted with Ubuntu 16.04

I wanted to deploy an app made in Angular 8 with Apache, I put the .htaccess in the folder of my Angular project and it did not work, I activated the a2enmod rewrite it restarted and neither.

I managed to fix it by doing these simple steps, which BSB comments

1) run the command: sudo nano /etc/apache2/sites-enabled/000-default.conf

2) Type AllowOverride All at the end of the 000-default.conf file that we just opened in console

Obviously it should be before the label

3) Restart the Server

---- Optional -----

  • Apart from this, in my index.html file of my Angular project, in the base tag put the name

base href = "/ name /"

And in the .htaccess file too, at the end, place

RewriteRule ^ /name/index.html

And ready this will work perfectly

----------

Saludos tenia el mismo problema en un VPS que contraté con Ubuntu 16.04

Quería desplegar una app hecha en Angular 8 con Apache, coloqué el .htaccess en la carpeta de mi proyecto Angular y no funcionaba, activé el a2enmod rewrite reiniciaba y tampoco.

Logré solucionarlo haciendo estos sencillos pasos, que comenta BSB

  1. sudo nano /etc/apache2/sites-enabled/000-default.conf 2. Colocar al final del archivo 000-default.conf que acabamos de abrir en consola

AllowOverride All

Obviamente debe ser antes de la etiqueta

  1. Reiniciamos el Servidor listo

---- Opcional -----

A parte de esto en mi archivo index.html de mi proyecto Angular en la etiqueta base coloque un nombre, de esta manera

base href="/nombre/"

Y en el archivo .htaccess también, al final colocar

RewriteRule ^ /nombre/index.html

Y listo esto funcionará perfectamente

Share:
13,875

Related videos on Youtube

MSVKC
Author by

MSVKC

More focused ...

Updated on September 18, 2022

Comments

  • MSVKC
    MSVKC over 1 year

    I want to use .htaccess for rewriting of php web pages. Or in a simple way "I don't want to use .php extension" to access any web page.

    .htaccess file (Ubuntu 14) which was working perfectly:

    RewriteEngine on
    #remove the need for .php extention
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php
    

    Same .htaccess file is not working after upgrade of AWS which is now in Ubuntu 16.04. I tried everything like changing the permission, enabling the rewrite mode, changing the config file Directory property from 'AllowOverride None' to 'AllowOverride All'.

    After some sort of experiment I found to be amend the above .htaccess file as below and it worked fine. But here it always allow to access only given php page. But I don't want to be specific with any given php page. I tried writing regexp as well but didn't work. And it always redirect to the given page only.

    <IfModule mod_rewrite.c><
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule . index.php [L]
    </IfModule>
    

    Can someone help me on this. Thanks in advance.

    • George Udosen
      George Udosen about 7 years
      I see a > syntax error in the IfModule code