Chapter in this post:
PHP offers the possibility to define redirects and redirects to other URLs with the command "header ()". You can actually only pass the URL to which the forwarding should take place as a parameter. To make the whole thing a little more transparent, I have a few examples from practice.
Please do not forget: in front of the code in the text file a " "which I leave out here for the sake of clarity ... Also important: There must be NO output in the browser before the call. That means before the"
header ('Location: http://www.example.com/beispiel-unterseite.html'); exit ();
If you want to create a google-friendly redirect, for example to redirect subpages that have been renamed to the new address, then you put the status code 301 in front of it, which tells the Google bot that it is a permanent redirection. Otherwise PHP will automatically send a 302 header code stating that it is only a temporary redirect.
header ("HTTP / 1.1 301 Moved Permanently"); header ('Location: http://www.example.com/beispiel-unterseite.html'); exit ();
As a rule, I use the SEO-friendly 301 redirect, which makes it clear to the search engines that the page you are surfing can be found permanently under a new URL. In practice, this often happens when the URL structure or file names change. And of course there is no short-term change here, but a permanent one.
Jens has been running the blog since 2012. He appears as Sir Apfelot for his readers and helps them with problems of a technical nature. In his free time he drives electric unicycles, takes photos (preferably with his iPhone, of course), climbs around in the Hessian mountains or hikes with the family. His articles deal with Apple products, news from the world of drones or solutions for current bugs.