One, Apache + PHP to make custom 404 page method.
The first thing to do is to deal with files that don't really exist, by using Apache's . htaccess definition,
The method is to create a new. Htaccess, at the beginning of. Htaccess Plus: ErrorDocument 404/404.php (/404.php is a custom 404 page).
Second, under the YII framework set
When the requested page does not exist, Yii throws a Chttpexception exception, the exception code is 404, then how to handle this kind of exception in Yii, there are three ways:
1, do not do anything, Yii will deal with itself
When this class exception is thrown, Yii defaults to render the errorxxx.php (error404.php) template file under framework/view/
2, under Protected/views/system new errorxxx.php,yii will go to render the file
3. Configuring the exception handler
In configuration file main.php, add the following configuration, set the exception handling controller to Site/error
' ErrorHandler ' =>array ( //use ' site/error ' action to display errors ' erroraction ' = ' site/error ', ) ,
Then add the error controller to the sitecontroller.php:
Public Function Actionerror () { if ($error =yii::app ()->errorhandler->error) {print_r ($error); if (Yii::app ()->request->isajaxrequest) echo $error [' message ']; else $this->render (' Error ', $error); } }
Finally, add the error.php template file under view/site/:
Pagetitle=yii::app ()->name. '-Error '; $this->breadcrumbs=array ( ' Error ', ); ? > Error
The above describes the PHP Project Unified Settings 404 page (including the YII framework), including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.