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

162
Vistas
Using dynamic URL on a site that is staticly hosted without query params

I’m currently trying to create a website that is static. Using JavaScript I make a request to my API and get the content for the page. But my issue is I don’t want the links to be using query params like example.com/list?item=item-id I want it to be example.com/list/item-id.

A good example of my question would be how to recreate the express routing app.get('/list/:item_id') with links on a static website where the server won't throw a 404 because the page doesn't exist but it will route exaple.com/list/item1 and example.com/list/item2 to the same page where the client-side javascript will determine whether the page exists.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It depends on which webserver you are using to host your static site. Here is one way of doing it with a static site hosted on Apache:

.htaccess:

# Allow static files to have extended paths
AcceptPathInfo On
# Default charset
AddDefaultCharset utf-8
# Make sure that an HTML file name "list"
# (with no .html extension) gets the right content type
AddType text/html list

list (an HTML file saved without a .html extension):

<!doctype html> 
<html>
  <head>
    <script>
      alert(location.pathname)
    </script>
  </head>
  <body>
    HELLO WORLD
  </body>
</html>

I tested this configuration on my Apache server. When I visit https://example.com/list/item-id, Apache serves the contents of /list as HTML. The JavaScript in that HTML alerts /list/item-id.

Your JavaScript would have to parse the item id out of the pathname and call your API with it.


There are other techniques that you could use to serve a single HTML file for many different paths. It is very common to use a front controller powered by a rewrite rule. You might also be able to use multiviews to acheive the same results with Apache's content negotiation module.

You'll need to find similar techniques if you want to host the static content on other web servers like Nginx or IIS.

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