3

I've got a setup that has been stable for years. Suddenly I'm getting File does not exist in the apache error log on items that should be getting processed by mod_rewrite.

Last night I did a package update on php/mysql (not apache) but I rolled back and it's still having the issue. .htaccess and apache config hasn't been touched.

I'm still looking for clues but I've got almost nothing so far.

It seems like anything we hit from inside our local network (which is a different network than the one the server is hosted on) never has an issue. If I hit it from my phone off wifi I am seeing the problem sometimes.

All of the File does not exist paths are valid for mod_rewrite to process. I can hit them without issue.

A bit perplexed and at a loss as to what to look for next.

I inherited this config and I've tried not to touch it but here's what we've got for this vhost.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteRule ^(.*)$ http://www.domain.com$1 [R=301,L]

In the public folder there is also a .htaccess with a lot of config. Here's a relevant chunk:

RewriteEngine On
RewriteBase /

#Correct some bad external links
RewriteRule ^lh$ / [L,R=301]

<FilesMatch "^cart$">
                ForceType application/x-httpd-php
</FilesMatch>

I've turned mod_rewrite logging up to 9 and matched one of the requests in the apache error log.

init rewrite engine with requested uri /cart/ViewItem/6054668
applying pattern '^(.*)$' to uri '/cart/ViewItem/6054668'
RewriteCond: input='www.domain.com' pattern='!^www.domain.com' => not-matched
pass through /cart/ViewItem/6054668
[perdir /home/user/domains/domain.com/public_html/] add path info postfix: /home/user/domains/domain.com/public_html/cart -> /home/user/domains/domain.com/public_html/cart/ViewItem/6054668
[perdir /home/user/domains/domain.com/public_html/] strip per-dir prefix: /home/user/domains/domain.com/public_html/cart/ViewItem/6054668 -> cart/ViewItem/6054668
[perdir /home/user/domains/domain.com/public_html/] applying pattern '^lh$' to uri 'cart/ViewItem/6054668'
[perdir /home/user/domains/domain.com/public_html/] pass through /home/user/domains/domain.com/public_html/cart
Matt
  • 141
  • 7
  • Have you confirmed that mod_rewrite is still being processed? If you enable error logging of mod_rewrite, what do you see? The fact that this problem seems "intermittent" and only experienced by "some" users would suggest something external to your immediate config? What else do the mod_rewrite directives do? The ones in your question are not essential to the running of the site. – MrWhite Nov 30 '16 at 18:51
  • It is being processed most of the time. This seems intermittent. I just noticed sometimes the browser is prompting to download the php file as text. The rewrite is a bandaid on some bad legacy code. The original implementer has php files named 'cart' with no extension, and this is how they forced it to be processed as PHP. We did see it happen from our internal network so that has nothing to do with anything. I'll see if I can bump up mod_rewrite logging and report back. Thanks for the reply. – Matt Nov 30 '16 at 19:02
  • @w3dk I've added some relevant log. – Matt Nov 30 '16 at 19:13
  • That error log snippet looks OK. Does that request correspond to a 404? What does the error log look like when you get a 404? Or when prompted to download the PHP file?! The intermittent nature of this seems "strange". If you are being prompted to download the PHP file then it would seem the `` wrapper is not matching? Or is this a different file that is being downloaded? What if you request `/lh`? – MrWhite Nov 30 '16 at 20:07

1 Answers1

1

Here's what I did to fix it.

  1. I ditched all the FilesMatch/ForceType stuff.
  2. I renamed all the files that didn't have extensions to .php
  3. I changed .htaccess to include two rules per file (which can probably be combined down into one)

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^cart$ ./cart.php
RewriteRule ^cart/(.*)$ ./cart.php`

The other problem I started having was the ssh2 pecl extension was causing segfaults. I upgraded it and it fixed the segfaults but it was no longer functional. I replaced it all with phpseclib. I'm still seeing some pecl zip.so segfaults. I still don't understand what caused all this but I wouldn't upgrade to php 5.6.28 on centos 6.8 right now. This is now a known problem: http://paul-m-jones.com/archives/6439

Matt
  • 141
  • 7