28

I'm having the following issue on a host using Apache 2.2.22 + PHP 5.4.0

I need to provide the file /home/server1/htdocs/admin/contents.php when a user makes the request: http://server1/admin/contents, but I obtain this message on the server error_log.

Negotiation: discovered file(s) matching request: /home/server1/htdocs/admin/contents (None could be negotiated)

Notice that I have mod_negotiation enabled and MultiViews among the options for the related virtualhost:

<Directory "/home/server1/htdocs">
    Options Indexes Includes FollowSymLinks MultiViews
    Order allow,deny
    Allow from all
    AllowOverride All
</Directory>

I also use mod_rewrite, with the following .htaccess rules:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^\./]*)$ index.php?t=$1 [L]
</IfModule>

It seems very strange, but on the same box with PHP 5.3.6 it used to work correctly. I'm just trying an upgrade to PHP 5.4.0, but I cannot solve this negotiation issue. Any idea on why Apache cannot match contents.php when asking for content (which should be what mod_negotiation is supposed to do)?

UPDATE: I noticed that mod_negotiation behaves correctly with files with extension different than .php: so if I'd have a file named /admin/contents.txt, I can access it regulary with the browser with /admin/contents url. So the problem is only for php files. Any clue on what could make the negotiation fail?

4
  • How do you configure mod_negotiation? Are you using it? Mar 23, 2012 at 13:56
  • 1
    Well I just include mod_negotiation in httpd.conf, then the MultiViews options in the VirtualHost should be enough to do what I'm looking for, as far as I know.. isn't it? Mar 23, 2012 at 13:58
  • 4
    FWIW, I had this problem with +MultiViews enabled, and it dissapeared upon disabling it. Jan 26, 2015 at 12:37
  • Adding Options -Multiviews at the top of .htaccess file worked for me on Ubuntu 22.04, Apache 2.4.57, php7.4-fpm (not prefork module, but event module with php-fpm as fastcgi handler). The other option - namely, adding "AddType application/x-httpd-php php" in mods-enabled/mime.conf or /etc/mime.types did not work. See this for MultiViews: bennadel.com/blog/…
    – site80443
    Feb 28 at 14:00

5 Answers 5

48

I found the solution. Very easy, indeed. I forgot to include the following:

AddType application/x-httpd-php .php

into apache mod_mime section into httpd.conf

I was misled by the fact that php scripts were correctly working; however the negotiation was failing because mod_negotiation only looks for "interesting" (and known) file types.

6
  • 4
    This! This right HERE! Spent most of the night hunting down why I was getting the very unhelpful "Discovered File(s)/None Negotiated" error. Scripts had been working fine before, and I had a devil of a time tracking down the fact that the type wasn't being included in mod_mime on the distribution I was testing on. I owe you a beer sir.
    – Akoi Meexx
    Feb 19, 2013 at 3:22
  • I'll gladly accept your beer when I'll come to US :) Feb 19, 2013 at 10:21
  • this works perfectly!! @lorenzo.marcon thanks for the question and answer!
    – rogcg
    Jun 27, 2013 at 1:50
  • 1
    This must have changed at some point. I'm feeling pretty confident I didn't need to add this earlier for php MultiViews to work. Sep 24, 2013 at 15:44
  • Thanks a metric ton! I was banging my head against the wall, wondering why my mod rewrite from search/?$ to search.php wasn't working. Seems the negoitiation module has precedence over the rewrite module which is generally good to know. Oct 19, 2018 at 11:25
13

I had the same problem after updating from Debian Squeeze to Wheezy. The mods-enabled/mime.conf includes the known file types from the system:

TypesConfig /etc/mime.types

The problem was that the /etc/mime.types file was replaced by the update and in the replaced file, the PHP part was commented out. When searching for it, I found:

#application/x-httpd-php                        phtml pht php
#application/x-httpd-php-source                 phps
#application/x-httpd-php3                       php3
#application/x-httpd-php3-preprocessed          php3p
#application/x-httpd-php4                       php4
#application/x-httpd-php5                       php5

I had to remove the # from each line containing php-relevant stuff, then save and restart the Apache web server. That solved the problem without modifying the mime.conf file.

3
  • 1
    This saved me after 4hs of unending debugging against a ghost.
    – MarkSkayff
    Jun 15, 2018 at 0:47
  • 2
    Be aware that doing this might make libapache-mod-php5 execute files with .php in the name (like filename.php.jpeg) which was the original rationale for commenting them out. See bugs.debian.org/589384
    – Kevinoid
    Jul 8, 2019 at 16:04
  • @Kevinoid This is a very big security issue. Thanks!
    – site80443
    Feb 28 at 13:37
6

Instead of mapping .php to a media type (which can have security implications, as described in Debian Bug 589384 which disabled them), you can configure MultiviewsMatch to match files without a type for .php, as suggested in Mark Amery's answer to a similar question:

<Files "*.php">
    MultiviewsMatch Any
</Files>
2

I had the same problem after updating from Debian Squeeze to Wheezy. The mods-enabled/mime.conf includes the known file types from the system:

 TypesConfig /etc/mime.types

The problem was that the /etc/mime.types file was replaced by the update and in the replaced file, the PHP part was commented out. When searching for it, I found:

#application/x-httpd-php                        phtml pht php
#application/x-httpd-php-source                 phps
#application/x-httpd-php3                       php3
#application/x-httpd-php3-preprocessed          php3p
#application/x-httpd-php4                       php4
#application/x-httpd-php5                       php5

I had to remove the # from each line containing php-relevant stuff, then save and restart the Apache web server. That solved the problem without modifying the mime.conf file.

1

I am working with Xammp with virtual hosts, the error with mod_rewrite was remove in httpd-vhosts.conf at <Directory "YourPath">

Instead

Options Indexes FollowSymLinks MultiViews

Put

Options Indexes FollowSymLinks

Source: https://www.lawebdelprogramador.com/foros/Apache/1422809-solucionado-Negotiation-discovered-files-matching-request.html

Greetings.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .