Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

41
Views
Is a 301 redirect the same as changing window.location?

I am a web developer who also works in SEO. I want to 301 redirect one page to another page. Is this 301 redirect for Google beyond what I write below for you?

In JavaScript:

<script> 
      window.location.replace("https://example.com");
</script> 

In PHP:

<?php 
    header("Location: https://example.com");
?>

Are these two 301 redirects, or do we have to write .htaccess in the cat file, for example?

7 months ago · Juan Pablo Isaza
2 answers
Answer question

0

You can not do this with JavaScript.

But you can use PHP as follows

<?php 
    header("Location: https://example.com", TRUE, 301);
    exit;
?>

Syntax header

header(header, replace, http_response_code)

7 months ago · Juan Pablo Isaza Report

0

Changing the URL with window.location in JavaScript is not a 301 redirect. JavaScript runs after the page has been generated on the server. Your JavaScript to change the URL would likely run on a page that has a 200 OK status.

That being said, Google treats JavaScript redirects very similarly to 301 permanent redirects. In most cases, Google will choose not to index the redirecting URL and pass the link juice from it to the target of the redirect.

On the other hand, clients that don't execute JavaScript won't see your JS powered redirect. That includes other search engines like Bing, Baidu, and Yandex, as well as broken link checkers and other SEO analysis tools.

Furthermore, even to Google, 301 redirects are a much stronger signal than a JavaScript redirect. Google is most likely to honor a redirect when it is a 301 Permanent variety compared to JS redirects, 302 Temporary redirects, or meta refreshes.

If you have the ability and opportunity to implement server side 301 Permanent redirects, you should do so instead of JS redirects.

7 months 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 job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.