Search code examples
php.htaccessurltrailing-slash

PHP able to access pages in root directory from a page with slash


We're having a problem with our PHP site: http://midlandssmilecentres.co.uk/

The problem is as follows, if you were to access, for example http://midlandssmilecentres.co.uk/feedback.php, and then put a trailing slash, it returns the index page of the root directory. From there, you can actually put any page, i.e. http://midlandssmilecentres.co.uk/feedback.php/feedback.php, and it will return that page. We need this behaviour to stop, or a feasible work around to stop these pages being accessible.

This is causing us lots of problems with duplicate content and pages that haven't been mobilised, due to the page trying to fetch the CSS from the wrong directory. We've tried removing all of the .htaccess files on the server, however this has not fixed the issue. I've done plenty of research on files with trailing slashes and how a file can be interpreted as a directory, but couldn't find anything that could help me with this.


Solution

  • With .htaccess, you can redirect all .php/... pages:

    RewriteEngine on
    RewriteRule ^(.+?\.php)/ $1 [NC,L,R=301]
    

    You also can change the apache configuration with:

    AcceptPathInfo Off
    

    But in this case a 404 error will be returned
    https://httpd.apache.org/docs/2.2/mod/core.html#acceptpathinfo