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

124
Vistas
Is there a way to treat ajax requests different than user requests in .htaccess?

Let's say I have /secret/example.php
In my .htaccess file I want to rewrite requests to /secret to /home.html using

RewriteRule secret /home.html

But now when I try to access /secret/example.php using ajax from example.js

var xhr = new XMLHttpRequest();
xhr.open('GET', '/secret/example.php', true);
xhr.onload = function(){
  console.log(xhr.responseText);
}
xhr.send();

It is also redirected and does not work.

Is there a way I can only rewrite requests made by the user (by typing www.example.com/secret in the search bar) and still allow ajax to access the file?

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

0

It is possible if you set additional header in xhr request: xhr.setRequestHeader("VIAXHR", "true");

Then in .htaccess something like this:

RewriteCond %{HTTP:VIAXHR} !^true$
RewriteRule secret /home.html
about 4 years ago · Juan Pablo Isaza Denunciar

0

Use RewriteCond before RewriteRule

RewriteCond documentation

Something like this:

RewriteCond %{REQUEST_URI} !^/secret/example.php$
RewriteRule secret /home.html
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