Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get original url for 404 page

Tags:

php

So I have found these two questions:

Accessing original URL in IIS7 404 redirect page Get URL of page requested that caused a 404

but they are both in different languages. Is there any way to get the address that caused something like a 404 message to use in a custom message?

for example if I requested example.com/example1 and that page wasn't there and it redirected to my error page, how could I get example1 to display in a message like The pageexample1isn't there, or use that to create the page example1?

like image 281
FabianCook Avatar asked Dec 26 '22 13:12

FabianCook


1 Answers

Since you are using PHP, you would be having access to the various PHP superglobals. $_SERVER['SCRIPT_NAME'], $_SERVER['REQUEST_URI'] etc can be used for the purpose. Something like this in the error page should do:

<?php
    printf("The page %s was not found.", $_SERVER['REQUEST_URI']);
?>

For more, do have a look at the $_SERVER superglobal documentation.

like image 130
Vaibhav Kaushal Avatar answered Jan 08 '23 02:01

Vaibhav Kaushal