Appearance
PHP header redirect 301 - what are the implications?
A 301 redirect in PHP using the header function tells the browser that the page has permanently moved to a new location. This is useful for redirecting old URLs to new ones or updating pages that have been relocated. The main implications of using a 301 redirect are:
- The browser will cache the redirect, so future requests for the old URL will automatically go to the new URL.
- Search engines will transfer their index entries to the new URL, updating search results accordingly.
- Users will be automatically directed to the new URL when they request the old one.
It's important to note that a 301 redirect passes link equity (ranking power) to the destination page. If the original page has strong SEO value, the new page will inherit it.
php
<?php
header("Location: https://example.com/new-page", true, 301);
exit;
?>Critical note: Always call exit (or die) immediately after header(). Without it, the PHP script continues executing, which can cause unexpected output or errors before the redirect takes effect.
Also, use a 301 redirect only when the resource is permanently moved. For temporary moves, use a 302 redirect, which tells browsers and search engines that the relocation is only temporary.