4

I have 5 production servers which are running FreeBSD 9.2, but we are planning on transitioning to CentOS. Because of this, I am attempting to set up some virtual machines to emulate our production server environment using CentOS 6.6. I have set everything up and it works great, save a single rewrite rule.

<Directory /var/www/html/www/trunk/amapi>
  RewriteEngine on
  RewriteRule  ^$ public/    [L]
  RewriteRule  (.*) public/$1 [L]
</Directory>
<Directory /var/www/html/www/trunk/amapi/public>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</Directory>
<Directory /var/www/html/www/trunk>
  RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*start\.php
  RewriteRule ^start.php/?(.*)$ $1 [R=301,L]

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ start.php/$1?%{QUERY_STRING} [L]
</Directory>

The first two rewrite rules are for a back end API using Phalcon, and they work perfectly in both environments. The third rewrite rule is a catch all to redirect all requests that don't match a real file to start.php which attempts to match them to a Phalcon module and then on to a 404 page if no route gets matched.

For some reason, it works under FreeBSD which is running Apache 2.2.27, but not under CentOS which is, for the moment, running Apache 2.2.15. This is a very simple rewrite rule which should work under either version of Apache with no problems, but apache keeps throwing a 404 when I attempt to access the file. Am I missing something? Obviously the SSL config and specific options are missing from the code displayed, but those are the order in which the reqrites appear in ssl.conf.

Thanks in Advance

Update: Apache Rewrite logs are:

10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (2) init rewrite engine with requested uri /letters/custom/test
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (3) applying pattern '^/attc2/(.*)$' to uri '/letters/custom/test'
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (3) applying pattern '^/forms/(.*)$' to uri '/letters/custom/test'
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (3) applying pattern '^/grafx/(.*)$' to uri '/letters/custom/test'
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (3) applying pattern '^/xport/(.*)$' to uri '/letters/custom/test'
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (3) applying pattern '.*' to uri '/letters/custom/test'
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (4) RewriteCond: input='' pattern='!.*mydomain.com/.*$' [NC] => matched
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (4) RewriteCond: input='/letters/custom/test' pattern='\\.(jpg|gif|png)$' => not-matched
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (1) pass through /letters/custom/test
Peter
  • 123
  • 1
  • 1
  • 7
  • So the problem is with the `RewriteRule ^start.php/?(.*)$ $1 [R=301,L]` rule, if I'm understanding correctly..? Can you clarify exactly what request you're sending (is it `/start.php/something` triggering the first rule, or `/something` triggering only the `RewriteRule ^(.*)$ start.php/$1?%{QUERY_STRING} [L]` rule) and what result you're expecting, versus what you're seeing from the error log when the 404 happens? – Shane Madden Feb 24 '15 at 20:54
  • @ShaneMadden It's basically a transitional tool as we move away from legacy code to an MVC. All requests that go to the document root, https://example.com/any_module/any_controller. Of course those don't map to real files or directories on the system, so they should get caught by that rewrite rule and silently passed to start.php which gets the request uri and figures out if there is a route that matches. If it does, it goes to the route, if not, it goes to a 404 page. – Peter Feb 24 '15 at 21:05
  • Ok, so what's in the error log when these 404s happen? – Shane Madden Feb 24 '15 at 21:07
  • @ShaneMadden a simple 404 error, same as if the rewrite rule didn't exist. – Peter Feb 24 '15 at 21:08
  • 1
    It should tell you what file it was looking for. That's relevant. – Shane Madden Feb 24 '15 at 21:09
  • @ShaneMadden It's looking for /var/www/html/www/trunk/controller/action which is a directry that doesn't exist, so that rewrite rule should pick it up and pass the request to start.php – Peter Feb 24 '15 at 21:14
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/21422/discussion-between-peter-and-shane-madden). – Peter Feb 24 '15 at 21:17
  • Right, so the rewrite isn't happening. Turn on `RewriteLogLevel 9` and set a `RewriteLog` location, let's see what it's actually doing. – Shane Madden Feb 24 '15 at 21:29
  • 1
    Well the main thing to note from your RewriteLog is that the rules it is applying are not in your original post. So either you have RewriteRules you don't know about, you didn't paste them all, or the request is being mapped to a location/vhost other than the one you think it is. – Unbeliever Sep 27 '16 at 07:43

1 Answers1

-1

I wonder if possibly the issue is just an unescaped dot. Try replacing this line:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*start\.php

With:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\.*start\.php
Kevin Roth
  • 101
  • 2