Forum Moderators: phranque
my .htaccess file:
RewriteEngine On
RewriteRule ^(.*)\/(.*)\/(.*)?$ /$1.htm [E=rwdone?yes,L]
ErrorDocument 404 /404.php
when i retrieve a page that does not exist, a normal 404 error is showed...but if i change the .htacces to:
RewriteEngine On
RewriteRule ^(.*)\/(.*)\/(.*)?$ /$1.htm [E=rwdone?yes,L]
ErrorDocument 404 /404.htm
and rename my 404.php to 404.htm it works...the php commands are showed like it was text, but the redirect at least works...
what i have to do to be able to use a custom 404 page dinamic? (php)
Options +Includes
RewriteEngine On
RewriteRule ^(.*)\/(.*)\/(.*)?$ /$1.htm [L]
ErrorDocument 404 /404.shtml
-----------------------------
the file worked but my php code was not executed (apache understands the file like a plain text file);;..
so i add the line:
AddType application/x-httpd-php .shtml
now apache does not use my 404 file and show the default page...
You want /404.php as your 404 errordocument? Then you must use "ErrorDocument 404 /404.php"
If it shows as plain text, that means that you have not told Apache to execute it server-side instead of just serving it as a "text file." So you will need to try both
AddType application/x-httpd-php .php AddHandler server-parsed .php If your code is in .htaccess, you also need to prevent an 'infinite' rewriting loop:
RewriteCond %{REQUEST_URI} !\.htm$
RewriteRule ^([^.]+)\/([^/]+)/([^/]+)$ /$1.htm [L]
Jim
my apache are executing php pages normally....but when i tried to use a php page as errordocument 404, apache just ignores it and show its default 404 page...i tried to use a 404.htm page instead of 404.php and then the my was used as error document...
it appears to me that somehow apache are blocking the use of php document on error document 404, because when i tried to tell apache to process .htm extension like a .php extension, he just ignores my error page and show the default on.
can you help -me?
my .htacces:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.htm$
RewriteRule ^([^.]+)\/([^/]+)\/([^/]+)$ $1.htm [L]
ErrorDocument 404 /404.php
my 404.php:
<html>
<body>
<h1> erro 404</h1>
</body>
</html>
when i envoke the url "http://pr:8080/sao-paulo/12/13" the rewrite rule works perfecly redirecting to sao-paulo.htm...but if i envoke:
[pr:8080...]
i got the default error page...and in the apache error log ive got just the message:
[Tue Sep 29 14:13:11 2009] [error] [client 127.0.0.1] File does not exist: C:/Projetos/PlanetaRestaurante/wwwroot/sao-paulo1.htm
RewriteEngine On
RewriteRule ^404\.php$ - [L]
RewriteCond %{REQUEST_URI} !\.htm$
RewriteRule ^([^.]+)\/([^/]+)\/([^/]+)$ $1.htm [L]
ErrorDocument 404 /404.php
It looks to me like your rule matches anything not ending in .htm, which would include 404.php. I'm not sure what you are doing with the rule exactly, so I'm not sure exactly how to tell you to make it better *, but the rule I added stops your 404.php page from being processed by your RewriteRule... It should work.
* I'm not sure why you need the 3 () when you are only referencing one and the first pattern matches everything up to the . (dot)
Dunno, Maybe?
RewriteRule ^([^.]+)\. $1.htm [L]
[edited by: jd01 at 5:35 pm (utc) on Sep. 29, 2009]
with your last try i stil got the same default error page, BUT in the apache error log, got this:
[Tue Sep 29 14:47:48 2009] [error] [client 127.0.0.1] File does not exist: C:/Projetos/Planeta1/wwwroot/sao-paulo.htm
[Tue Sep 29 14:47:48 2009] [error] [client 127.0.0.1] script 'C:/Projetos/Planeta1/wwwroot/404.php' not found or unable to stat
so the log is the same
[Tue Sep 29 14:52:45 2009] [error] [client 127.0.0.1] File does not exist: C:/Projetos/Planeta1/wwwroot/sao-paulo.htm
[Tue Sep 29 14:52:45 2009] [error] [client 127.0.0.1] File does not exist: C:/Projetos/Planeta1/wwwroot/sao-paulo.htm
[Tue Sep 29 14:52:45 2009] [error] [client 127.0.0.1] File does not exist: C:/Projetos/Planeta1/wwwroot/sao-paulo.htm
[Tue Sep 29 14:52:45 2009] [error] [client 127.0.0.1] File does not exist: C:/Projetos/Planeta1/wwwroot/sao-paulo.htm
[Tue Sep 29 14:52:46 2009] [error] [client 127.0.0.1] File does not exist: C:/Projetos/Planeta1/wwwroot/sao-paulo.htm
[pr:8080...]
my actual 404.php:
<html>
<body>
<h1> erro 404</h1>
</body>
</html>
Do be sure that your error page is at least 512 bytes long... Otherwise, IE will hide it and shows its own "Friendly error page"... Because of course, MS knows best. See [webmasterworld.com...]
I didn't even think of that problem because I don't use IE for anything except testing the non-standard CSS hacks that it requires...
Jim
Another example of trying to 'think for the user' and messing things up even more...
Yeah, I thought when I quit optimizing for them the headaches stopped, but I would not have guessed the answer was the toolbar in a week... I even know about the IE page size (was just reading about it in fact) and it didn't even cross my mind in this situation.
Somethin' new every day, and not always for the better...