Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 861
Mordad khezerlou Avatar asked Sep 01 '25 16:09

Mordad khezerlou


1 Answers

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)

like image 130
mehmet Avatar answered Sep 04 '25 06:09

mehmet