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

126
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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