Redirect invalid paths using .htaccess (e.g. "home.php/xyz")

1

1

I am running Apache 2.4.2 on my local server. My website's .htaccess file is as follows:

DirectoryIndex home.php
Options -Indexes
ErrorDocument 404 /404.php

This works great at displaying an HTTP 404 page when you try to access a non-existent file in the browser, but it is not showing the error page when accessing existing files using the following syntax:

http://localhost/<FileName>.php/<AdditionalCharacters>

For example, if I go to home.php/xyz, the home.php page loads, but all the relative links in the HTML are broken. I don't have a home.php directory on my server! What's going on?

Is there a directive or rule I can add to my .htaccess file to stop this behavior and throw an HTTP 404 error instead?

iglvzx

Posted 2013-01-26T04:04:25.860

Reputation: 21 611

Answers

1

This is a feature called "path_info", and is commonly used to run entire websites from a single CGI script (when better alternatives, such as mod_rewrite, are unavailable).

If the URL causes a CGI script to be treated as a directory, Apache will run that script normally but give it the extra path components in the PATH_INFO environment variable. Many wiki engines use this feature – for example, you can access https://wiki.archlinux.org/index.php/Beginners%27_Guide/Preparation this way.

This can be controlled using the AcceptPathInfo setting.

user1686

Posted 2013-01-26T04:04:25.860

Reputation: 283 655