I have a website say abc.com ,when I enter a wrong address like abc.com/somthing.php it shows a 404 not found but when I enter the address like abc.com/index.php/something.php it does not show the 404 error. Any suggestions?
-
1That might be happening because the webserver is finding the first file specified on your URL which is `index.php` – Claudio Jul 17 '19 at 20:36
-
1Possible duplicate of [Use 404 ErrorDocument that is in a sub directory](https://stackoverflow.com/questions/10087323/use-404-errordocument-that-is-in-a-sub-directory) – zod Jul 17 '19 at 21:34
2 Answers
The request
abc.com/somthing.php
gives you 404 because something.php file does not exist on the server.
On the other hand, the request
abc.com/index.php/something.php
gives you 404 only if index.php does not exist on the server. If abc.com/index.php
resides on the server, then it is accessed and the string /something.php
is actually treated as a variable, that can be read with the $_SERVER['PATH_INFO']
.
If your index.php
file looks like this
<?php
echo $_SERVER['PATH_INFO']
?>
and you access it using abc.com/index.php/something.php
then the output will look like something.php
.
For further info, feel free to check the documentation

- 1,809
- 2
- 20
- 27
-
So to display a error page if abc.com/index.php/something.php is clicked i have to check the $_SERVER['PATH_INFO']. If it is empty then nothing should be done else display a error.Or is there any better way to do it? – Mks Jul 18 '19 at 07:00
-
@Mks you can disable the behavior using the [`AcceptPathInfo`](https://httpd.apache.org/docs/2.4/mod/core.html#acceptpathinfo) directive. – misorude Jul 18 '19 at 07:31
-
Well, the thing is that, using your current settings, the request `abc.com/index.php/something.php` is send to the `abc.com/index.php` file, using the `/something.php` as a variable. You can change that setting from Apache (see comment above) or manage the error inside your php code. Probably the best way is handling the request from Apache (but that is just my opinion). – Cosmin Staicu Jul 18 '19 at 08:32
-
-
The short answer is: no 404 error is triggered on this case, since the required php file exists. More than that, there are 2 ways of managing this situation, as I have stated above. – Cosmin Staicu Jul 18 '19 at 14:44
https://www.digitalocean.com/community/tutorials/how-to-create-a-custom-404-page-in-apache
This should help
Keep in mind that the Apache looks for the 404 page located within the site's server root. Meaning that if you place the new error page in a deeper subdirectory, you need to include that in the line, making into something like this:
ErrorDocument 404 /error_pages/new404.html

- 12,092
- 24
- 70
- 106
-
The question is not about setting a error message. The op is misunderstanding the path leading to the php script with the variable send to the script. – Cosmin Staicu Jul 18 '19 at 05:09