Eu tenho um site usando o .htaccess para reescrever as regras, mas algumas não funcionam.
Este é o meu arquivo .htaccess:
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]
Mas eu tenho um erro por exemplo quando eu acesso www.domain.com/contacto ele me lança esse erro:
Not Found
The requested URL /contacto was not found on this server.
Mas se eu alterar o URL desse www.domain.com/contacto.php
, ele funciona.
Acho que essa regra da lista de baixo deve fazer o trabalho, não é?
# Paginas sin extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ $1.php [QSA]
Por que estou fazendo errado?
Estes são todos os módulos carregados para o meu 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)
E este é o meu arquivo domain.dev.conf
em /etc/apache2/sites-enabled
:
<VirtualHost *:80>
ServerAdmin [email protected]
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>
Ele estava funcionando bem no apache 2.2, mas após a atualização para 2.4 pára de funcionar.
Existe uma diferença entre o apache 2. E o 2.4 na forma de aplicar arquivos htaccess.