Troubleshooting Apache MultiView Option

In a previous article we shared instructions on how to use .htaccess to remove file extensions in the URI (Remove .php / .html extension from URL slug). While effective, this can introduce issues in .htaccess with redirects, and other options and rules you might deploy on your site.

A cleaner way to handle these file extensions is to use the MultiView option in Apache.

About MultiView Options for Apache

The MultiView option is actually a content negotiation rule in Apache, which means for it to work you will need the mod_negotiation module enabled. The MultiView options specifically helps hide extensions.

For example, let's say you have yourdomain.com/coolpage.php but you don't want the URI to show the ".php" extension. MultiView would help you clean it so that it looks like this: yourdomain.com/coolpage (notice the .php extension is gone).

Enabling and disabling can be as simple as adding the +MultiViews (to enable) or -MultiViews (to disable) directive in your apache2.conf, httpd.conf, virtualhosts, or .htaccess files.

This option is set to OFF by default, even when you use Options ALL so be prepared to explicitly declare the state you want it in.

Troubleshooting MultiView Option Issues

We've compiled a few of the issues we've run into, or seen some of our clients struggle with when it comes to using MultiView options.

1: Verify Negotiation Module is Enabled

Because MultiView is a content negotiation rule, you have to verify that the negotiation module is enabled.

The quickest way is to create a info.php file in a directory and add the following code:



<?php phpinfo() ?>
                        


Open the file in the browser and look for the loaded modules section:



NOC - Apache Loaded Modules

If it's not loaded, an easy way to enable it is to use the IfModule directive. It would look something like this in your file:

<IfModule mod_negotiation.c>
    Options +MultiViews
</IfModule>                        
						

2: Verify Correct Handlers are Accounted For

There might be an instance where you have configured everything correctly, but it's still not working. First place we recommend going, is your error logs. If you see something like this:

[Wed Jun 22 16:17:41.458297 2022] [negotiation:error] [pid 1143] [client IP] AH00687: Negotiation: 
discovered file(s) matching request: /var/www/yourdomain.com/path/file (None could be negotiated).
						


Then it's telling you it's unable to negotiate the conversion. In this instance, you might need to specify the type of files to negotiate. You can add this to your config file and it should do the trick:

AddType application/x-httpd-php .php .phtml .html .htm
						


When it is all said and done, here is an example of what it might look like in your apache2.conf file:

<Directory /var/www/yourdomain.com>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Require all granted
    AddType application/x-httpd-php .php .phtml .html .htm
</Directory>
						

3: File and Directory Conflicts

All is not always great with MultiView, there may be conflicts to aware of.

For example, if you have a file called example.php in root folder and you set up a rule in your htaccess for a virtual folder called example/ then you'll have a problem with your rule because the server will choose example.php automatically (if MultiViews is enabled, which is the case most of the time).

To get around this you will want to disable MultiView like this:

Options -MultiViews
						


And if it's a shared host, you might have to use the <IfModule mod_negotiation.c> directive as explained above.



Posted in   Application_Tips   Troubleshooting   Apache     by trunc_team

Improve Your Websites Speed and Security