Defect #4538

.htaccess redirect rules not working when multiple CGI/FastCGI modules enabled

Added by Wim Heirman almost 12 years ago. Updated about 10 years ago.

Status:NewStart date:2010-01-08
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Permissions and roles
Target version:-
Resolution: Affected version:

Description

I just noticed something strange, using the default .htaccess file, when both mod_cgi and mod_fcgid were enabled. These are the default rewrite rules:

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
<IfModule mod_fastcgi.c>
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
</IfModule>
<IfModule mod_fcgid.c>
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
</IfModule>
<IfModule mod_cgi.c>
       RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
</IfModule>

With both mod_cgi and mod_fcgid, this translates to:

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

This means: non-static files are served through dispatch.fcgi (as expected), but when the RewriteCond doesn't match (i.e. it's a request for an existing static file) the request is sent through to the 2nd RewriteRule -- which ends you up with lots of CGI processes all not able to serve your images/CSS.

A better solution would be to use something like this, to make sure that only one RewriteRule can be active:

<IfModule mod_fastcgi.c>
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
</IfModule>
<IfModule !mod_fastcgi.c>
    <IfModule mod_fcgid.c>
        RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
    </IfModule>
    <IfModule !mod_fcgid.c>
       <IfModule mod_cgi.c>
          RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
       </IfModule>
    </IfModule>
</IfModule>

History

#1 Updated by Etienne Massip about 10 years ago

  • Category set to Permissions and roles

Also available in: Atom PDF