1

I want to show a 404 page when a User goes to:

example.com/example.php

and show a password page when a User goes to:

example.com/example.php?show

What would be the best way to show a Default 404. The one which the server generates.

Edit: Apache Version 2.2

John
  • 45
  • 6
  • Use the rewriting module most http servers come with. It allows you to implement rules and match requests against patterns. Then you can redirect / rewrite the requests any way you want to. For the apache http server start here: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html – arkascha Aug 20 '13 at 08:14
  • I want to do this from within the php file if possible. – John Aug 20 '13 at 08:16
  • Much less efficient, but as you like: just sent the 404-headers or forward the browser to your servers 404 page by sending a location header. – arkascha Aug 20 '13 at 08:18

1 Answers1

0

What would be the best way to show a Default 404. The one which the server generates.

I assume you're using the Apache Webserver second version (probably this needs 2.2 or higher).

To get the wbeservers default 404 page do a redirect with the 404 code. This works in multiple places (for example in mod_rewrites' RewriteRule with R=404 flag at the very end):

But also for other directives with redirect that allow you to pass the redirect code.

For example the Redirect directive (second line from end):

# mask 403 on .ht* as 404
<Files ~ "^\.ht">
  Order Deny,Allow
  Allow from all
  Satisfy All
  Redirect 404 /
</Files>

The you commented:

I want to do this from within the PHP file if possible.

AFAIK sending an internal redirect is not possible from PHP. You can try to figure out which the default response is - and in case it is from a static HTML file - include that file from within PHP.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836