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.
Best Answer
You need to disable
MultiViews
(or simply not enable it). For example: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 forfiles.php
(without the additional pathname information that is required for your request to be successful) before mod_rewrite gets to test the request. So theRewriteRule
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).