Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I have a user accessing my site for example:, is there any way to grab the "testpage.html" as a string if the testpage.html doesn't exist? (I want to make custom 404 error messages..Basically I want when the user goes to a page that doesnt exist, say "This page [pagename] doesnt exist" and display a search result with the pagename as the query.)

share|improve this question

closed as off topic by random Jan 31 '13 at 5:19

Questions on Super User are expected to relate to computer software or computer hardware within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 2 down vote accepted

Generally if you want to do anything useful with dynamic content, you're going to need some sort of interpreted language to provide the logic. As you did not specify, I assume you'll be using PHP.

In the case of PHP, you have access to the $_SERVER superglobal which, among other bits, exposes REQUEST_URI (e.g. $_SERVER['REQUEST_URI']) which is exactly what you are looking for. You can then build some logic in your PHP script around this variable to do actions based on specific matched URIs.


if ($_SERVER['REQUEST_URI'] == "/testpage.html") {
  // Do something here

You could, of course, also get fancy with regular expressions, case statements, etc.

share|improve this answer
Where would this php script be stored? – agz Jan 31 '13 at 4:59
1 would probably be a good start. :) – Garrett Jan 31 '13 at 6:31

It sounds like your real question is "How do I make a custom 404 page", yes? That's going to be web server dependent.

As to extracting parts of the URL, if you're using PHP then you want the parse_url() function. In Perl, you'd use the URI module

share|improve this answer

Not the answer you're looking for? Browse other questions tagged .