Freelance Web Developer

: Available for hire to work on projects of all sizes and types. Get in touch for a quote.

Permanent redirects are an important tool not only for general PHP development but also for Search Engine Optimisation. To a general user the browser simply forwards on to the new URL, probably without you even noticing. To search engine crawlers they are also forwarded but provided extra information that the page they are visiting has permanently moved to the new address. If this was Google for example, Googlebot would notice the change and drop the old URL from it’s index and begin indexing the new one.

So, what’s the point in a 301 permanent redirect and how does it differ to a standard redirect? If you needed to change the way a URL is structured from, for example, index.php?page=1 (very non-SEO friendly) to /web-development-gloucestershire/ (SEO friendly) then you can inform search engines of the change. Without the permanent redirect the first page will either fail and produce a ’404 Not Found’ or be identical to the new page – thus causing duplicate content issues.

The permanent redirect differs from a standard redirect because of the way it is informing search engines of the change. Without this it would become a temporary redirect or standard redirect. This means that search engines will keep the original page in it’s index because it is expecting the redirect to be removed at some point soon.

To create a 301 permanent redirect in PHP you use the following two lines of code, it’s really that easy.

<?php
    header('HTTP/1.1 301 Moved Permanently');
    header('http://rosstanner.co.uk/');
?>

Remember, this must be placed at the very top of the script. More specifically, before any HTML content or output is produced. This is because PHP uses the headers, which are called before any output, in order to complete the redirect.

Is there a limit on how many 301 redirects I can use on my website?

In short the answer is no, there isn’t a limit. However there is a limit on ‘chained redirects’ as Matt Cutts from Google explains.



If you are running an Apache server you can achieve this using .htaccess too. If you don’t have access to edit this file within your online files then consult your webmaster.

One Response to PHP & SEO – Permanent redirect using PHP header – HTTP 301

  1. daniel says:

    this blog helped me loads. thanks PAL

Leave a Reply

Your email address will not be published. Required fields are marked *


2 + = nine

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

%d bloggers like this: