punctweb

Topic: function.redirect_to.php

Hey all,

[This is not a bug]

Here is my modification of the function.redirect_to.php file and a little suggestion regarding the SEO features (explanation will follow):

Code:

function redirect_to($url, $status = '')
{
    switch($status) {
        case '404':
            header("HTTP/1.1 404 Not Found");
            header('Location: ' . $url);
            break;
        case '301':
            header("HTTP/1.1 301 Moved Permanently");
            header('Location: ' . $url);
            break;
        default:
            header('Location: ' . $url);
            exit;
    }    
}

and a small modification in index.php (Line 198)

Code:

redirect_to(BASE_URL . 'page-unavailable/', '404');

Explanation: if you access a link that does not exists (let's say BASE_URL/bla-bla/), you get redirected to the "page-unavailable/" but the headers sent are 200 - OK, which, for Google or other search engines, means that the page actually exists and can be indexed.

So, if you specify the '404' code, the headers will send the 'Not Found' status and the link is not indexed.

Also, i did added the '301' status code, which means that the page was permanently moved from a location to another. I'm thinking here at moving, let's say, a job from a category to another (by the way, can this be done ? ).

That's it, thank you for your attention smile

filipcte

Re: function.redirect_to.php

Thanks for this, @punctweb!
You're absolutely right.

Original jobberBase author
www.filipcte.com

jlhenry

Re: function.redirect_to.php

Hello,

Sadly it's not working for me.

I've replace the ./app/index.php line 198 with:
redirect_to(BASE_URL . 'page-unavailable/', '404');

I've replace replace ./app/_includes/function.redirect_to.php with :
function redirect_to($url, $status = '')
{
    switch($status) {
        case '404':
            header("HTTP/1.1 404 Not Found");
            header('Location: ' . $url);
            break;
        case '301':
            header("HTTP/1.1 301 Moved Permanently");
            header('Location: ' . $url);
            break;
        default:
            header('Location: ' . $url);
            exit;
    }
}

Here is a dump of my live-http-headers log:

----------------------------------------------------------
http://quebec.emploisdulibre.net/sfsdhgahefhds

GET /sfsdhgahefhds HTTP/1.1

Host: quebec.emploisdulibre.net

User-Agent: Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.0.5) Gecko/2008121622 Ubuntu/8.10 (intrepid) Firefox/3.0.5 Ubiquity/0.1.3

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

HTTP/1.x 302 Found

Date: Thu, 08 Jan 2009 21:29:21 GMT

Server: Apache

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

Location: http://quebec.emploisdulibre.net/page-unavailable/

Content-Length: 0

Keep-Alive: timeout=15, max=100

Connection: Keep-Alive

Content-Type: text/html; charset=UTF-8

----------------------------------------------------------

http://quebec.emploisdulibre.net/page-unavailable/

GET /page-unavailable/ HTTP/1.1

Host: quebec.emploisdulibre.net

User-Agent: Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.0.5) Gecko/2008121622 Ubuntu/8.10 (intrepid) Firefox/3.0.5 Ubiquity/0.1.3

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3

Accept-Encoding: gzip,deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive: 300

Connection: keep-alive

HTTP/1.x 200 OK

Date: Thu, 08 Jan 2009 21:29:21 GMT

Server: Apache

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

Keep-Alive: timeout=15, max=99

Connection: Keep-Alive

Transfer-Encoding: chunked

Content-Type: text/html; charset=UTF-8

--------------------------------------

Have you got any idea how I can debug?

mneylon

Re: function.redirect_to.php

I tried this modification as well, but it still returns a HTTP status of 200 and not 404 sad