Redirect to 301

Hi

My site lists pages from mysq using php, if i remove a record from the database I then want that to be 301, but at the moment it just displays a default error message. The code for the error is this

if (empty($name)) return $this->Error('Error: Invalid Page!');

How can I change this to 301 and so remove from search engines

Thanks John

Could you send the code for the Error function?
Also, where do you want to 301 to?
301 is redirect. Don’t you mean 404?

Hi Thanks for the reply

Not sure I have any error code apart from what I showed you

I want to 301 as this is Moved permanently and will be dropped from search engines etc

Do I need to get the fuction to do this??


Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location: http://www.new-url.com" ); 

Thanks John

The Error() function has to be somewhere in you system, otherwise it can’t be executed. It’s definitely not a part of the PHP core.

Beside from that, 301 is really the wrong code to use here.
301 is for Moved permanently, but for the scenario you’re describing the content is REmoved permanently, which is something else entirely, and the website should reply with a 404 Not Found (which I’m guessing is what the Error() function does).

Take a look at section 10.3.2 of rfc2616 if you don’t believe me.

Yes. Moved Permanently isn’t the same as REMoved Permanently. You are expected to provide the location where the resource moved to with a 301 redirect.

404 is what you want.

Edit: What ScallioXTX said :stuck_out_tongue:

Great minds … :wink:

Hi

Ok I understand it needs to be 404 now

I think I have found the error code

	function Error($message, $type = 0) {

		$vars = array();

		$vars['message'] = $message;

		$vars['type'] = $type;

		if ($type == 1) $vars['class'] = 'textGreen';

		else $vars['class'] = 'textRed';

		return $this->Parse('error.html', $vars);

	}

I see from this it has a error.html, this file is in my root here is the code for that

<div class="error" ><img src="images/icon_msg_{TYPE}.gif" width="16" height="16"><span style="vertical-align:top"><strong>{MESSAGE}</strong></span></div>

Is this error file the one that should have the 404 info in?

Thanks John

The error function looks like it handles lots of different types of error, not just 404, so you’d need something in there to tell you it is a 404 error you want to generate to start with. Once you know it’s a 404 error, you can use the header() function to set the 404 header.

I’d say so you need to put the 404 code in the Error() function.

header(“HTTP/1.0 404 Not Found”);

Thanks for your help, I think I know what to do now