0

I have the following in a virtualhost section:

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/local.mysite/wordpress/$1

In my testing, I found that adding a rewrite rule of RewriteRule ^/wordpress/wp-content/(.*)$ /wp-content/$1 [L] had no effect for a URL like :

http://local.mysite/wordpress/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=....

Is this because all requests containing .php in the name are passed to fcgi and so all rewrite rules are ignored?

1
  • It might simply be a question of order, if the ProxyPassMatch comes before your RewriteRule.
    – HBruijn
    Commented Feb 27, 2015 at 8:36

1 Answer 1

1

If you use a proxypassmatch or proxypass it passes the php script to be processed by the php-fpm process and the php-fpm process ignores .htaccess rules. One way to avoid it is to use apache sethandler as is explained in this answer https://serverfault.com/a/672969/189511,

 <FilesMatch \.php$>
   SetHandler "proxy:unix:/path/to/socket.sock|fcgi://unique-domain-name-string/"
 </FilesMatch>

I'll copy the full solution here

After hours of searching and reading Apache documentation I've come up with a solution that allows to use the pool, and also allow the Rewrite directive in .htaccess to work even when the url contains .php files.

<VirtualHost ...>

 ...

 # This is to forward all PHP to php-fpm.
 <FilesMatch \.php$>
   SetHandler "proxy:unix:/path/to/socket.sock|fcgi://unique-domain-name-string/"
 </FilesMatch>

 # Set some proxy properties (the string "unique-domain-name-string" should match
 # the one set in the FilesMatch directive.
 <Proxy fcgi://unique-domain-name-string>
   ProxySet connectiontimeout=5 timeout=240
 </Proxy>

 # If the php file doesn't exist, disable the proxy handler.
 # This will allow .htaccess rewrite rules to work and 
 # the client will see the default 404 page of Apache
 RewriteCond %{REQUEST_FILENAME} \.php$
 RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
 RewriteRule (.*) - [H=text/html]

</VirtualHost>

As per Apache documentation, the SetHandler proxy parameter requires Apache HTTP Server 2.4.10.

I hope that this solution will help you too.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .