Apache .htaccess没有正确执行

I referred to various sites and even many stackoverflow questions, but I am unable to find any solution to this. I have a .htaccess file in /var/www/html/mail/ directory. I also have a file named sample.php. I want extensions to get removed. But my rewrite rule in .htaccess file is not working. It is neither giving any error. But I can surely say that the file is executing. I tried putting some random text in it. It returned a internal server error. I am not sure what exactly the error is. I also changed the AllowOverride in apache2.conf to all. My .htaccess code is

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

I am following this tutorial https://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

Any help is acceptable. Thanks in advance