Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda