Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
How to .htaccess pseudo-static + hidden extension?

Why can't I use the following?

RewriteRule ^(.*)$ $1.html [L]

.htaccess file:

RewriteRule ^(.*)$ index.php [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L]
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

RewriteRule ^(.*)$ index.php [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L]

The first rule rewrites everything to index.php. The directives that follow are effectively ignored.

However, the second rule also rewrites everything (same pattern ^(.*)$ - obvious conflict), that doesn't map to an existing file or directory to append a .html extension. This second rule is more restrictive.

It seems that what you want to do is:

  1. Append the .html extension to URLs that would map to .html files.
  2. Rewrite all other requests that (I assume) do not map to physical files and directories to index.php.

Additional assumptions

  • The .htaccess file is located in the document root.
  • Requested URLs that should map to .html files do not contain dots in the URL-path. Therefore, dots in the URL-path indicate file extensions only.
  • If you literally rewrite everything else to index.php (as you were doing) then it will also rewrite all your static resources (CSS, JS, images, etc.), so I assume you want to make exceptions for static resources and anything that would otherwise map to a file or directory.

Try the following instead:

RewriteEngine On

# Append the ".html" extension if the target file exists
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^([^.])$ $1.html [L]

# Rewrite other requests that don't map to files/directories to index.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !\.(?:css|js|jpg|png|gif)$ index.php [L]
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda