简体   繁体   中英

How can I get my Yii2 404 page to display on live server

I customized the 404.php page in the view folder of my Yii installation. Works very very on local server showing the website header and footer and the customized content on the 404.php page.

However, when I uploaded to the live server, the 404.php page is not displayed when page is not found, instead a plain white page with the message - Sorry! This page does not exist Sorry! This page does not exist - is displayed. How can I fix this?

Obviously, the view/404.php is not being used. The content of my error.php is below:

<?php

/* @var $this yii\web\View */
/* @var $name string */
/* @var $message string */
/* @var $exception Exception */

use yii\helpers\Html;

$this->title = $name;
?>
                <!----Section Title Starts---->
                <div class="article-title-wrapper uk-section uk-section-primary">
                    <div class="uk-container">

                        <div class="uk-width-5-6@l uk-margin-auto">

                            <div class="uk-flex uk-flex-center">
                                <div class="section-intro uk-width-1-1 uk-width-2-3@l uk-text-center" uk-scrollspy="target: > div; cls:uk-animation-fade; repeat: true">
                                    <div class="page-title">
                                        <h1 class="uk-article-title">Page Not Found</h1>
                                    </div>
                                </div>
                            </div>
                        </div>          
                    </div>
                </div>  
                <!----Section Title ends---->

                <!----Section Content Starts---->
                <div class="article-content uk-section uk-section-default uk-padding-remove-bottom">
                    <div class="uk-container">
                        <div class="left-indent">
                            <div class="uk-width-5-6@l uk-margin-auto">
                                <div class="uk-flex uk-flex-center">
                                    <div class="section-content uk-width-1-1">
                                        <article class="uk-article uk-margin-large-bottom uk-text-center">
                                            <p class="uk-text-large">Sorry, but the page you were trying to view does not exist.</p>
                                        </article>
                                    </div>
                                </div>

                                <hr class="double">                     
                            </div>
                        </div>                      
                    </div>
                </div>  
                <!----Section Content ends---->

I have checked the answers given here but it does exactly address my issue. I did not change the default configuration for displaying error. The default configuration according to Yii2 will use - YOUR_APP/views/site/error.php to display errors. This works on my local server but is not working on live server which is my question.

UPDATE : I have two internet connection. I switched my internet connection and I suddenly discovered that the 404 page was coming up normally. I switched back to the other connection and the problem returned. I have switched back and forth and it is clear that for unknown reason, I can get the correct 404 page on one internet connection while it does not work in the other. This doesn't seem normal.

I then used a VPN on the internet connection that is not bringing the right 404 page and it worked well too. Is there a security feature rejecting certain types of connection?

You need to set following in web/index.php or for advanced app browse to frontend/web/index.php

defined('YII_DEBUG') or define('YII_DEBUG', false);

OR

You can throw custom error with status code. For Example,

throw new \yii\web\NotFoundHttpException(status code);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM