Forum Moderators: phranque
Currently whenever a user types in the wrong URL, the address automatically redirects / changes to the location of the 404 page (i.e. example.com/blah -> example.com/errors/404.php). I'd like for the URL to remain the same while the site loads up the 404 page, but I have yet to figure that out. I figured I could use the REQUEST_URI command in the script:
<html>
<body><h1>404 File Not Found</h1>
<hr>
<p><i><?php
echo $_SERVER['REQUEST_URI']
?></i></p>
</body></html>
404 File Not Found
_________________________________/errors/404.php
After Googling for a while, I came across a couple of .htaccess tricks [corz.org] and tips [garnetchaney.com] that never quite panned out the way I hoped. I tried tons of permutations with no success; most of the time I got this stupid message: "Redirection limit for this URL exceeded. Unable to load the requested page."
Here's an example of my current .htaccess file:
ErrorDocument 403 http://example.com/errors/403.php
ErrorDocument 404 http://example.com/errors/404.phpRewriteEngine On
Options Indexes Includes +FollowSymLinks ExecCgi# The following commented lines would not behave itself.
# (It was later punished and sent to bed without supper.)# RewriteBase /
# RewriteCond %{REQUEST_FILENAME}!-f
# RewriteCond %{REQUEST_FILENAME}!-d
# RewriteRule ^(.*)$ /$1 [R=301,L]AddType text/vnd.wap.wml wml
AddType image/vnd.wap.wbmp wbmp
AddType text/vnd.wap.wmlscript wmls
AddType application/vnd.wap.wmlc wmlc
AddType application/vnd.wap.wmlscriptc wmlsc
AddHandler server-parsed wml txt
AddType application/x-httpd-php .phpDirectoryIndex index.php index.shtml index.html index.htm index.cgi index.wml
-Danny
Yes, sorry, reading the documentation...
The ErrorDocument [httpd.apache.org] description clearly states that you must use a local URL-path and not a canonical URL if you wish the server to return the correct server response code. Otherwise, it will return a 302 redirect response code.
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
Jim