Unique631
Unique631

Reputation: 101

How to control the address that the user enters and show 404

image

I want to show the 404 page when user enters unknown address like on the above image.

I can control the unknown address after index.php but don't know how to do this for the part before the index.php part.

I wrote this code to control what user enters after index.php

<?php
$pageName = 'places';
if (isset($_GET['page'])) {
$pageName = $_GET['page'];
}

$pageList = array(
    'places',
    'places_info',
    'save'
);

if (!in_array($pageName, $pageList)) {
$pageName = '404';
}
?>

Upvotes: 1

Views: 386

Answers (1)

Rohit Gupta
Rohit Gupta

Reputation: 4193

It looks like you have apache on your development machine.

The way to have custom error pages is

  1. Create/Edit the file in C:\xampp\htdocs\blit\.htaccess
  2. Insert a line ErrorDocument 404 /blit/404.shtml
  3. Create the file C:\xampp\htdocs\blit\404.shtml
  4. Put whatever html you want in it.
  5. Repeat for other errors.

If you type in localhost/blit/xxy and xxy.php and xxy.html do not exist then the error page will be shown.

Upvotes: 1

Related Questions