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

210
Visualizações
How to redirect using Javascript on all WebPages

I am trying to copy this website: https://pslk.net/testtest, it redirects to https://pastelink.net/testtest using javascript and not server-side redirect.

I know how to redirect using .htaccess:

RewriteEngine on
RewriteRule ^(.*)$ https://example2.com/$1 [R=301,L]

and Javascript:

<script>
location.href = "https://example2.com" + document.location.pathname; 
</script>

But I want to redirect using javascript not htaccess. so My question is: Where should I put my javascript code above for it to be executed on all web pages?

Because I tried to place it in index.html and it did not redirect on all web pages. It will only redirect if I visit the index.html

For example, if I visit this link: example.com/test it should redirect to example2.com/test. but I can't just create multiple folders on my website containing that javascript I am tired , there are multiple numbers of combinations on the website's pathname, and I don't think this website created multiple folders with that javascript redirect: https://pslk.net/testtest2

Sorry I am VERY new on this, Thanks.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

I tried this solution, and now it works:

On .htaccess:

RewriteEngine on
ErrorDocument 404   /index.php

On index.php

<script>
location.href = "https://example.com" + document.location.pathname; 
</script>

So, on a blank website with only index.php exist. Whatever you type on your website's pathname will go to the 404 page. you can set the Custom 404 page using htaccess and from index.php you can now set the Javascript wildcard redirect. Please tell me if you have best alternatives. Thanks

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try it with a timeout function:

<html>
   <body>
      <script>
         setTimeout(function(){
            window.location.href = 'https://stackoverflow.com';
         }, 3000);
      </script>
      <p>Redirect after 3 seconds.</p>
   </body>
</html>
about 4 years ago · Juan Pablo Isaza Relatório

0

sm3sher is right. You'll have to put the script-tag and its content within the body tags and it should be the last item there.

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