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

264
Visualizações
.htaccess : loading of JS in another directory is blocked by CORS

I'm trying to call a javascript file in another directory of the same server but I'm blocked by CORS policy while my htaccess shouldn't prevent that.

I have mydomain.com pointing to /directory1/ where index.php captures all the requests:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [NC,L,QSA]

If I call a JS file inside /directory1/, it will send me back to index.php. That's why I have moved the js file to another directory /directory2/ and I'm simply calling that JS with:

<script src="mydomain.com/directory2/test.js" type="module"></script>

in that directory, I have a .htaccess file with the following content:

<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>

RewriteEngine On
RewriteCond %{ENV:HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Accessing the file directly into the browser works but accessing it from the script src doesn't work.

I have a CSP in directory1 using the following directive:

Header set X-XSS-Protection "1; mode=block" Header always append X-Frame-Options SAMEORIGIN Header set X-Content-Type-Options: "nosniff” Header set Content-Security-Policy "default-src 'self' 'unsafe-inline' 'unsafe-eval' *mydomain.com" Header set Referrer-Policy "same-origin"

Am I missing something somewhere? I don't get a CSP error, I get a CORS error so I suppose my CSP is not the issue here.

Thanks

about 4 years ago · Juan Pablo Isaza
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