What's happening here is that your rewrite is actually working, but the R=301 is causing a second iteration which causes the 404.
The request comes in for images/chart.png
and your rewrite rules go to work. When it matches on your first rule, it causes a 301 redirect. This 301 redirect tells the browser to issue a new request for /static/images/chart.png
.
So the new request makes it to your server, and the rewrite rules are executed again. This time, the request doesn't match your custom rules at the top and makes it into the CodeIgniter rule. Since your new URL begins with "static", it matches the CI rule and redirects to /index.php?/static/images/chart.png
. Since CI doesn't have a clue how to handle this (I assume), it tosses out the 404 to inform the user it can't find the resource.
What you're going to want to do is to update the CI rule to add the following conditions:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
This will tell mod_rewrite to only execute the rule if the request isn't for a literally existing file (!-f
) or directory (!-d
).
Once this update is made, the first rule will cause the same redirect for /static/images/chart.png
but since that file literally exists at that path, the CI rules will leave it alone, and no new rewriting will be done. The server will then serve up the image normally.