Htaccess redirect of 404 error just prints filename, doesn’t execute file

.htaccessapache-2.2errordocumenthttp-status-code-404redirect

On an Apache host, I have a folder called /thumbs with a program in it called program.php that I will use to create thumbnails.

There is a .htaccess file that contains the following lines:

options -indexes
errordocument 404 program.php

What should happen is that when I call /thumbs/image1.jpg, program.php should be executed.

What actually happens is that the browser just echoes the name of the program. Calling /thumbs/image1.jpg results in the browser showing:

program.php

and no code is executed.

I have used this technique on many other sites and it has worked, but not this time.

Anybody know why this might be the case?

Best Answer

The ErrorDocument directive can be used several ways, depending on the syntax. To execute a file the way you want, you must use the full path relative to the DocumentRoot, preceded with a /. Otherwise, it's taken to be a literal message to be displayed, which is what is happening for you.

Try this:

 ErrorDocument 404 /thumbs/program.php

More info here: http://httpd.apache.org/docs/2.2/mod/core.html#errordocument

Related Topic