Linux Mint - Apache 2.4 .htaccess rewriteRule不起作用

I have a site using .htaccess to rewrite rules but soem does not work.

This is my .htaccess file:

RewriteEngine On
RewriteBase /
# Inicio
RewriteRule ^inicio|home|index$ index.php [QSA,L]

# Paginacion amigable
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.([0-9]+)$ $1?pag=$2 [QSA,L]

# Miniaturas
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\/)?tdd([A-Za-z0-9_~-]*)\/(.*)$ imagen.php?param=$2&src=$1$3 [QSA,L]

#paginas
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*-p([0-9]+)$ interna.php?id=$1 [QSA]

#Intranet
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*-i([0-9]+)$ intranet.php?id=$1 [QSA]

#publicaciones
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*-n([0-9]+)$ publicaciones_detalle.php?id=$1 [QSA]

# Paginas sin extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ $1.php [QSA]

# sitemap
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule sitemap.xml sitemap.php [QSA]

# Buscador
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^search$ buscar.php [QSA]



# En caso de no existencia
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ 404.php [QSA]

# Paginas incluidas en el template
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} ^.*\.php$
RewriteRule ^(.*)$ plantilla.php?uri=$1 [QSA]

But I have an error for example when I access www.domain.com/contacto it throws me this error:

Not Found

The requested URL /contacto was not found on this server.

But If I change the url like this www.domain.com/contacto.php it works.

I think this rule from the bottom list should do the job isn't it?

# Paginas sin extension
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.+)$ $1.php [QSA]

Why I'm doing wrong?

These are all the modules loaded for my apache:

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php7_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)

And this is my domain.dev.conf file on /etc/apache2/sites-enabled:

<VirtualHost *:80>
    ServerAdmin webmaster@domain.dev
    DocumentRoot /var/www/html/domain/
    ServerAlias www.domain.dev
    ServerName domain.dev
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory /var/www/html/domain>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
                RewriteEngine On
    </Directory>
</VirtualHost>

It was working fine on apache 2.2 but after upgrade to 2.4 stops working.

Is there a difference between apache 2. And 2.4 in the form of applying htaccess files

Thank you

Add this rule to take care of the .php.

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

Change this block:

# Paginas sin extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ $1.php [QSA]

to this:

# Paginas sin extension
# (if exists)
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [QSA,L]

For the purposes of enhancement and adhering to the DRY principle, replace your entire .htaccess file with the code below instead:

RewriteEngine On
RewriteBase /

# Ignorar archivos y directorios
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [END]

# Inicio
RewriteRule ^inicio|home|index$ index.php [QSA,L]

# Paginacion amigable
RewriteRule ^(.+).(\d+)$ $1?pag=$2 [QSA,L]

# Miniaturas
RewriteRule ^(.*/)?tdd([A-Za-z0-9_~-]*)/(.*)$ imagen.php?param=$2&src=$1$3 [QSA,L]

# paginas
RewriteRule ^.*-p(\d+)$ interna.php?id=$1 [QSA,L]

# Intranet
RewriteRule ^.*-i(\d+)$ intranet.php?id=$1 [QSA,L]

# Publicaciones
RewriteRule ^.*-n(\d+)$ publicaciones_detalle.php?id=$1 [QSA,L]

# sitemap
RewriteRule ^sitemap.xml$ sitemap.php [QSA,L]

# Buscador
RewriteRule ^search$ buscar.php [QSA,L]

# Paginas incluidas en el template
# RewriteCond %{REQUEST_FILENAME} -f
# RewriteCond %{REQUEST_FILENAME} ^.*\.php$
# RewriteRule ^(.*)$ plantilla.php?uri=$1 [QSA]

# Paginas sin extension
# (En caso de existencia)
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [QSA,L]

# En caso de no existencia
RewriteRule ^.*$ 404.php [QSA]

There, I have removed all duuplicate references to conditions that check if the request does match an existing file or folder - you only really need to do that once, and then stop rewriting if it does match. I would recommend turning it off for directories (by removing line 6: RewriteCond %{REQUEST_FILENAME} -d) for the purposes of security.

As you can see, I have commented out that block mentioned in my comment on your original question as it does not seem to have a specific function - you'll need to fix that to get it to work.