Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using a shared web hosting service. Running phpinfo, I can see the Server API shows CGI/FastCGI rather than Apache 2 Handler.

In this article:

It says 'If your server is configured to run PHP as an Apache module, then you will have the choice of using either php.ini or Apache .htaccess files, however, if your server runs PHP in CGI mode then you will only have the choice of using php.ini files locally to change settings, as Apache is no longer in complete control of PHP.'

I think it's really strange that the rewrite rules in the .htaccess that I created have been working perfectly while it's running in CGI mode. Why is this happening?

share|improve this question
up vote 1 down vote accepted

The problem is not that Apache rewrite rules in the .htaccess file won't work when running PHP as a CGI vs. an Apache module. It's just you can't use the .htacess file to set PHP values when it's ran as a CGI. Instead you have to have a separate php.ini file that has your settings changed in it. Within my own shared hosting account, which runs PHP as a CGI, I make use of FastCGI and have the following in my .htaccess file:

<IfModule !>
    AddHandler myphp-script .php
    Action myphp-script /cgi-bin/myphp.fcgi

Then in my accounts /cgi-bin/ directory I place the myphp.fcgi script with chmod 755 containing:


# This ensures PHP doesn't try to run it's own
# process manager.  

# Execute PHP with my php.ini config file
exec /path/to/system/cgi-bin/php -c ~/myconf/php.ini

I still have a <IfModule mod_rewrite.c> section in my .htaccess file to handle rewriting some old URI paths to the new URI structure to maintain old links that are cached in search engines.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.