I'm building an MVC framework in PHP. I'm using segmented URLs like so:
http://mydomain.com/controller/method/param1/param2
I'm using the following rewrite rules in Apache .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&method=$2¶m1=$3¶m2=$4 [NC,L]
The URLs work fine and the correct controllers and methods are being called. However, I'm getting lots of errors in the apache2 error.log. Anytime I access a URL with two or more segments I get a "file not found" error. There are no 404s happening in the browser.
Just to clarify, the following URL does not cause errors in the Apache log.
http://dev.bonesphp.com/about
However, the following URL will cause an error:
http://dev.bonesphp.com/about/test/pre>File does not exist: /var/www/vhosts/dev.bonesphp.com/about
My php.ini error settings are set to E_ALL / STRICT
Does anyone know how to fix this?
Thanks in advance!
UPDATE: 5/12/2013
I enabled the rewrite log in Apache. This is what the rewrite log says when I try to access the above URL:
127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] add path info postfix: /var/www/vhosts/dev.bonesphp.com/about -> /var/www/vhosts/dev.bonesphp.com/about/test 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/about/test -> about/test 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$' to uri 'about/test' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (2) [perdir /var/www/vhosts/dev.bonesphp.com/] rewrite 'about/test' -> 'index.php?controller=about&method=test¶m1=¶m2=' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (3) split uri=index.php?controller=about&method=test¶m1=¶m2= -> uri=index.php, args=controller=about&method=test¶m1=¶m2= 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] add per-dir prefix: index.php -> /var/www/vhosts/dev.bonesphp.com/index.php 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (2) [perdir /var/www/vhosts/dev.bonesphp.com/] strip document_root prefix: /var/www/vhosts/dev.bonesphp.com/index.php -> /index.php 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (1) [perdir /var/www/vhosts/dev.bonesphp.com/] internal redirect with /index.php [INTERNAL REDIRECT] 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a3508/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/index.php -> index.php 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a3508/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$' to uri 'index.php' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a3508/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/index.php -> index.php 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a3508/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '(^|/)\.' to uri 'index.php' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a3508/initial/redir#1] (1) [perdir /var/www/vhosts/dev.bonesphp.com/] pass through /var/www/vhosts/dev.bonesphp.com/index.php 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] add path info postfix: /var/www/vhosts/dev.bonesphp.com/about -> /var/www/vhosts/dev.bonesphp.com/about/favicon.ico 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/about/favicon.ico -> about/favicon.ico 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$' to uri 'about/favicon.ico' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] add path info postfix: /var/www/vhosts/dev.bonesphp.com/about -> /var/www/vhosts/dev.bonesphp.com/about/favicon.ico 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/about/favicon.ico -> about/favicon.ico 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '(^|/)\.' to uri 'about/favicon.ico' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (1) [perdir /var/www/vhosts/dev.bonesphp.com/] pass through /var/www/vhosts/dev.bonesphp.com/about 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a1290/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/404.html -> 404.html 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a1290/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$' to uri '404.html' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a1290/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/404.html -> 404.html 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a1290/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '(^|/)\.' to uri '404.html' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a1290/initial/redir#1] (1) [perdir /var/www/vhosts/dev.bonesphp.com/] pass through /var/www/vhosts/dev.bonesphp.com/404.html