5

I have a windows environment using WAMP where this works fine. I am just setting up my Ubuntu desktop development environment, and this particular mod_rewrite is not working.

It's pretty basic, but if I go to
example.local/files/a-real-file.pdf I get a 404 not found from apache. If I go to
example.local/files.php/a-real-file.pdf the file will display, as expected. If I go to
example.local/files.php/non-existing-file.who.cares I get a var_dump($thelink) as expected from my files.php logic.

the .htaccess in my web root

RewriteEngine On
RewriteRule ^files/(.*)$ files.php/$1

my apache vhost config

<VirtualHost *:80>
    ServerName reqapp.localhost
    DocumentRoot /var/www/html/aaApp/public_html
    <Directory /var/www/html/aaApp/public_html/>
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

and for good measure, the "localhost" conf

<VirtualHost *:80>
    ServerName localhost
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

as well as the "applicable" part of apache2.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

according to phpinfo() mod_rewrite is loaded. If a create a syntax error in the .htaccess file, the site does crash.

I don't know where else to look. I can't fine any other .conf files in and of the "{mods|conf|sites}-enabled" files that should be effecting this directory.

It might be worth mentioning that I also have a Joomla instance running, and the SEF is working fine with it.

1 Answer 1

4
Options +Indexes +Includes +FollowSymLinks +MultiViews

You need to disable MultiViews (or simply not enable it). For example:

Options +Indexes +Includes +FollowSymLinks -MultiViews

Or remove it altogether from the Options directive if it is has not already been enabled on the server.

With MultiViews enabled, mod_negotiation will trigger an internal subrequest for files.php (without the additional pathname information that is required for your request to be successful) before mod_rewrite gets to test the request. So the RewriteRule pattern never matches and the rewrite does not occur.

In detail...

MultiViews is part of mod_negotiation (content-negotiation). The issue in your case is that you are requesting /files/... (in a valid directory - the document root) and a file with that basename (ie. files) exists in that directory. If you were to request /bar/... (which presumably does not exist) then you would not have experienced this problem.

When you requested /files/..., MultiViews results in Apache searching for an appropriate resource (files.* - essentially trying various file extensions) until a response with the expected mime-type is found. The "problem" is that this happens very early in the request, so will often conflict with mod_rewrite.

MultiViews is a simple way of enabling extensionless URLs (no URL rewriting is required). However, as soon as you need to do something a little more complex then it will likely conflict with mod_rewrite - a common problem. MultiViews is not enabled on Apache by default (however, some shared hosts do enable it).

3
  • Awesome! that was it. I don't even know what MultiViews is. I just copied the section from what WAMP did. To be honest, I think I only need FollowSymLinks
    – Chad
    Mar 27, 2019 at 10:32
  • Yes, you probably only need FollowSymLinks (but you should explicitly disable Indexes with -Indexes since it is enabled for /var/www/) . Indexes allows Apache to generate directory listings (which is generally not desirable) and Includes enables SSI. I've updated my answer with more info about MultiViews.
    – MrWhite
    Mar 27, 2019 at 11:06
  • Thanks for the update! Always good to know the why!
    – Chad
    Apr 1, 2019 at 12:25

You must log in to answer this question.

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