404 error

when landing onto a wrong url (404 not found) Yii redirects to the error page, but the url is exactly the same. For example:

http://www.yiiframework.com/demos/blog/fjopdfjoidfjidfffjfj

This is duplicate content. Is it possible to achieve the error url to be for example http://mywebsite.com/errorpage ?

You can set the redirection to preferred page in action responsible for handling the errors. In config/main.php:


'errorHandler' => array(

            'errorAction' => 'site/error',

        ),

And in in actionError in SiteController you can redirect user to anything you want.

I already have the errorHandler set up. The actionError() just renders the error page like this:


	public function actionError()

	{

		$error=Yii::app()->errorHandler->error;

	

		if(Yii::app()->request->isAjaxRequest)

			echo $error['message'];

		else

			$this->render('error', $error);

	}

How can I redirect to the error view? Should I create another action?

Yes, and that’s the only standard compliant way to do it.

I don’t think so. Yii sets the appropriate HTTP Status header for all error pages which prevents duplicate content issues.

EDIT: For custom error handling, you may have to set the status header manually, but the "duplicate content" issue still only affects pages served with "200 Ok" status.

Yes, create another action and redirect to it in actionError. But as phtamas said this should not be necessary.

ok, if it isn’t necessary I won’t do it