views:

29

answers:

1

I noticed an odd (to me) mod_rewrite thing happening. Fixing it is not important to me so much as figuring out what's going on. Basically, I have an svg file called test.svg in my document root, as well as an index.php. My expectation, based on my .htaccess file is that visiting http://localhost/test.svg would get me the .svg file (and it does), while visiting http://localhost/test/action would be rewritten to index.php/test/action. Instead, the latter is apparently rewritten to test.svg/action, as I receive the message

The requested URL /test.svg/action was not found on this server.

Here is my .htaccess file:

# Turn on URL rewriting
RewriteEngine On

# Protect application and system files from being viewed
# RewriteRule ^(application|modules|system) - [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

I am using a Apache 2.2.12 on Ubuntu (installed via apt-get). I think my setup is fairly standard, but I'm not sure exactly what directives or config files would be relevant. I am by no means a sysadmin of any kind, I just use this server to test and develop things locally.

As I said, fixing this issue would be trivial, I just am often confounded by mod_rewrite and would like to understand what's going on here.

+2  A: 

Apache's HTTP content negotiation feature is automatically translating from "/test" to "/test.svg". See http://httpd.apache.org/docs/2.0/content-negotiation.html#multiviews

You can disable content-negotiation in .htaccess with the directive:

Options -MultiViews

You can get more information about what mod_rewrite is doing by adding these directives to your Apache configuration (they won't work in .htaccess):

RewriteLog /path/to/rewrite.log
RewriteLogLevel 3

The RewriteLogLevel can be any number from 0 (disabled) to 9 (extremely verbose). 3 should give you enough to see what's going on, but don't use that on a production server.

Stuart Sierra
Thanks, that did it!
notJim