Add error 404 friendly url

Asked

Viewed 350 times

2

Good

I am making the routes of the urls friendly by the htacess file and now I wanted to show the error 404 if the user type a name that does not exist.

But I don’t know how I can do it

I have the code that presents the contents like this

if(!isset($_REQUEST['controller']) || empty($_REQUEST['controller'])){
       require_once("conteudos/home.php");
        }else{
            require_once("conteudos/".$_GET['controller'].".php");
        }

1 answer

0


In php with the function curl_init();

$handle = curl_init($url);
curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);

/* Obtendo o arquivo que está conectado a $url. */
$response = curl_exec($handle);

/* Checando se há erro 404 (Arquivo não existe). */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
    /* Aqui está a resposta do erro 404. */
}

curl_close($handle);

  /* $response aqui. */

Unmanageable website Via .htacess: :

ErrorDocument 404 /404.html

Joomla:

if (($this->error->getCode()) == '404') {
  header('Location: /index.php?option=com_content&view=article&id=75');
exit;
}

Wordpress:

<?php
/**
 * The template for displaying 404 pages (Not Found)
 *
 * @package WordPress
 * @subpackage Twenty_Thirteen
 * @since Twenty Thirteen 1.0
 */

get_header(); ?>

    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">

            <header class="page-header">
                <h1 class="page-title"><?php _e( 'Not Found', 'twentythirteen' ); ?></h1>
            </header>

            <div class="page-wrapper">
                <div class="page-content">
                    <h2><?php _e( 'This is somewhat embarrassing, isn’t it?', 'twentythirteen' ); ?></h2>
                    <p><?php _e( 'It looks like nothing was found at this location. Maybe try a search?', 'twentythirteen' ); ?></p>

                    <?php get_search_form(); ?>
                </div><!-- .page-content -->
            </div><!-- .page-wrapper -->

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_footer(); ?>
  • I did not put it like this Errordocument 404 /contents/error.php

  • solved one part but the other I think I’ll have to check in the database if there is the item you typed or shows error 404

  • What is happening to me and that now for example http://exemplo.pt/comer the eating and the name of an article that well of the database if I put http://exemplo.pt/comer/efw it already presents the error but if put http://example.pt/wef it does not show the error and shows the file I will have to check in the database to see if the name exists and ?

  • No php mysql root site

Browser other questions tagged

You are not signed in. Login or sign up in order to post.