Home Blog Archive Internet Redirect in PHP: how to set up the forwarding

Redirect in PHP: how to set up the forwarding

  • Jan 30, 2026
  • 790
  • 0

In this practical tip we show you how to set up a Redirect in PHP, and so the visitor automatically to another website.

Setting up the Redirects in PHP: Status 301 or 302?

Server will be forwarded side via PHP to another website, this happens by default with the status code 302.
  • The status code 302 indicates, however, that the page will be forwarded only temporarily. A permanent redirect is signaled through the status code 301.
  • For the visitor, this makes no difference - he will be redirected to any event, automatically on the other site.
  • Very interesting is this difference, however, for search engines. A Robot from Google or other search engines gets transferred to the Status of 302, he assumes that this redirect is only temporarily.
  • With the note of the status codes 301, the search engine receives the indication that is under the old URL no longer has to be sought, but the permanent Redirect. Simplified, this means that the Index can be the old address for now against the new ones.
  • So the search engine when crawling perhaps the new content of the website has been redirected does not need to start from the beginning.
Redirect in PHP: status code is important

To set up a Redirect in PHP

The PHP Code must be at the beginning, before any other output to the Browser must be done.
  • Make sure, therefore, that before the php Tag, neither "echo" nor a accidental character stands being empty. Exactly what PHP is, we will explain in another post.
  • To create a Redirect to another web page, enter the following Code:
  • "www.domain.de" replace it with your old URL, and "der-neue-name.php" refers to the website, which is to be forwarded.
  • The "exit" you should insert on every case. It binds under a possibly incorrect execution of the next line.
How about PHP, inserting an image, we show you in our next practice tip around the program.

YOU MAY ALSO LIKE

0 COMMENTS

LEAVE A COMMENT

Human?
1 + 3 =