Question

What is the php path for an Ubuntu 14.04 droplet?

Good day everyone,

I was wondering if you could tell me how I could make this line work in my htaccess (both versions):

ErrorDocument 404 /apps/{NAME}/public/404.php
ErrorDocument 404 /404.php

Basically the 404 is in my /public folder (root directory) and that’s what I’d like to link to in the .htaccess. I’ve tried searching the topics here and I can’t figure out what exactly I’m asking for. The “php path” sounds like the best bet? Lol. ;-)

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @GreenKi,

If you haven’t seen this already, ServerPilot has an article on customizing Apache error messages.

This format does work:

ErrorDocument 404 /404.php

assuming you have a file called “404.php” in your app’s “public” directory.

Note that you can’t use the ErrorDocument directive to catch 404’s for requests that end in “.php” themselves. That is, if a file is requested such as “/this-does-not-exists.php”, that won’t get handled by the ErrorDocument directive because the request ends in “.php”. To handle 404s for requests that end in “.php”, you should use rewrite rules that direct those requests to a specific php script which can send a 404 response.

For example, adding this in your .htaccess file will show a custom 404 page (using a file named “404.php”) for requests for php scripts when the requested script doesn’t exist:

RewriteRule ^404\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.php [L]

Then in that 404.php script you would have something like:

<?php
header("HTTP/1.0 404 Not Found");
// generate the HTML of the response here
?>

If you’re still having problems with this, you can open a ticket with ServerPilot.

Hello there!

That sounds about right or that you are on the right track. If it does not work, the problem may lie in how you are handling your general .php requests (catch-all vs. specific php files). If you are just handling “index.php”, the redirect to handle your new php error page might not be served properly.

Hope this helps! :)