Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!