Apache 2.4 with PHP-FPM .htaccess redirection

6,199

Your problem is that the .htaccess file is never read. .htaccess is only read after apache has determined that it needs to look for the resource requested on its local filesystem. You are however telling apache to forward the request to another process...

You will need to add the rewrites to your main config.

Share:
6,199
nwalke
Author by

nwalke

Updated on September 18, 2022

Comments

  • nwalke
    nwalke almost 2 years

    I have Apache 2.4 set up with PHP-FPM on a server. To pass from Apache to PHP-FPM I use the following:

    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9001/hosting_files/site.com/admin_secure/$1
    

    "admin_secure" is the DocumentRoot in the vhost.

    In that directory, I have a .htaccess file that contains the following:

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteRule    ^$    webroot/    [L]
        RewriteRule    (.*) webroot/$1    [L]
     </IfModule>
    

    The site works, right up until I try to access something that should be in the webroot directory. For example, if I go to vendors/kcfinder/browse.php which is inside the webroot directory, I get a "File not found" error. If I go to webroot/vendors/kcfinder/browse.php, it works.

    I've turned on rewrite and proxy logging, and it looks like the rewrite never takes place. It just sends whatever I type in the URL (if it's a PHP file).

    Is there a way to write my ProxyPassMatch statement to take in rewrites like that?

  • Kontrollfreak
    Kontrollfreak over 10 years
    Either that or dump mod_proxy_fcgi and use mod_fastcgi.