How to make a PHP Redirect?

You can use the “header” function to do the needed, as simple as below:

header('Location:', true, 301);

However, there is other methods you may use to redirect your page to another one, Like using JavaScript:


Or using Meta refresh redirection:

 <meta http-equiv="refresh" content="0;url=">

Anyway, it’s up to you to use which method that serves your needs, so if you used the PHP method, that means you are using it within your models or functions, or it is within a complicated logic that trigger such action, like logout cases.

As for the JavaScript method, it will be great if you your application logic is mainly written in any front-end technology, then it will make sense then to use the JavaScript line.

While using the meta refresh method, it will save the hassle as simple as putting one line in a page that is already moved to another one.

SEO Perspective:

Since you are using the redirection in your pages, old or new ones, so that means that you are affecting this page position in search engines, so be careful to consider if this page is important then it’s better to use the PHP or .htaccess redirect with 301 to let search engines bots know that your page is moved not removed.

Another point to consider as well is, dealing with google search console to change this url as well quickly and easily to make sure you are not affected, specially if you are dealing with high-ranked pages on search engine results.