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

130
Visualizações
Nextjs static export redirecting issue

I have an issue with redirecting in my Next.js app.

I did static export (next build && next export).

Host of the app is located in the subdirectory (https://www.myhost.com/subdirectory/**[index.html here]**) so I used basePath: '/subdirectory' in next.config.js. Everything works just right on first sight.

Redirecting inside the app works just fine. But when user refresh the page on the other page then index - let's say the page is named subpage (https://www.myhost.com/subdirectory/subpage) the site doesn't redirect the user to subpage but rather goes to https://www.myhost.com/ (not even to the subdirectory in which the project is located).

I would very much appreciate someones help.

Here is .htaccess file.

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html/ [L]

</IfModule>

If u need any other file, I can edit this post if u comment it.

Thanks in advance!!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm assuming your .htaccess file is located at /subdirectory/.htaccess. These directives are written as if the app is in the document root, not the subdirectory.

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html/ [L]

</IfModule>

The last RewriteRule directive sends all requests to the document root. You need to:

  1. Remove the slash prefix on the substitution string (/index.html/)
  2. And remove the trailing slash. (Ordinarily this would result in a 404, unless path-info is enabled?)
  3. Remove the RewriteBase directive altogether.
  4. The <IfModule> wrapper is not required.

Taking the above points into consideration, try the following instead:

# /subdirectory/.htaccess

RewriteEngine On

RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . index.html [L]
about 4 years ago · Juan Pablo Isaza 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