How to make mod_rewrite works for Slim on first path of URI

Hi All,

I’ve recently struggled in writing rule of mod_rewrite of Apache httpd v2.4.7.
Here is what I thought of rewriting the PATH_INFO for Slim to dispatch the handler from virtual host to directory.

My idea is try to filter the first directory of URI by the rewrite rule set in virtualhost directive, and suppose that the PATH_INFO variable which is updated and should be passed to next rewrite rule (used by Slim, set in Directory directive).
i.e.

  1. request is /my_vhost/version
  2. after mod_rewrite set in VirtualHost context, the PATH_INFO is changed to ‘version’
  3. URI ‘version’ is then passed to Slim at directory context for handler dispatching

But with my modification on function ‘defaultNotFound’ of Slim.php, the getResourceUri () which is from PATH_INFO is not changed to ‘version’ as I expected. The PATH_INFO is still remained as ‘/my_vhost/version’.

Does anyone know how to make it happen?

— log from apache mod_rewrite —

[Mon Jun 06 16:52:49.004168 2016] [rewrite:trace2] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] init rewrite engine with requested uri /my_vhost/version
[Mon Jun 06 16:52:49.004218 2016] [rewrite:trace3] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] applying pattern ‘^/my_vhost/(.)’ to uri ‘/my_vhost/version’
[Mon Jun 06 16:52:49.004234 2016] [rewrite:trace2] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] rewrite ‘/my_vhost/version’ -> ‘/version’
[Mon Jun 06 16:52:49.004243 2016] [rewrite:trace5] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] setting env variable ‘PATH_INFO’ to ‘version’
[Mon Jun 06 16:52:49.004249 2016] [rewrite:trace2] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] forcing ‘/version’ to get passed through to next API URI-to-filename handler
[Mon Jun 06 16:52:49.004307 2016] [rewrite:trace3] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] [perdir /var/www/my_vhost/] strip per-dir prefix: /var/www/my_vhost/version -> version
[Mon Jun 06 16:52:49.004314 2016] [rewrite:trace3] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] [perdir /var/www/my_vhost/] applying pattern ‘^’ to uri ‘version’
[Mon Jun 06 16:52:49.004327 2016] [rewrite:trace4] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] [perdir /var/www/my_vhost/] RewriteCond: input=’/var/www/my_vhost/version’ pattern=’!-f’ => matched
[Mon Jun 06 16:52:49.004333 2016] [rewrite:trace2] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] [perdir /var/www/my_vhost/] rewrite ‘version’ -> ‘index.php’
[Mon Jun 06 16:52:49.004338 2016] [rewrite:trace3] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] [perdir /var/www/my_vhost/] add per-dir prefix: index.php -> /var/www/my_vhost/index.php
[Mon Jun 06 16:52:49.004347 2016] [rewrite:trace2] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] [perdir /var/www/my_vhost/] strip document_root prefix: /var/www/my_vhost/index.php -> /index.php
[Mon Jun 06 16:52:49.004362 2016] [rewrite:trace1] mod_rewrite.c(468): [rid#7fbe7c3280a0/initial] [perdir /var/www/my_vhost/] internal redirect with /index.php [INTERNAL REDIRECT]
[Mon Jun 06 16:52:49.004397 2016] [rewrite:trace2] mod_rewrite.c(468): [rid#7fbe7c324ee0/initial/redir#1] init rewrite engine with requested uri /index.php
[Mon Jun 06 16:52:49.004408 2016] [rewrite:trace3] mod_rewrite.c(468): [rid#7fbe7c324ee0/initial/redir#1] applying pattern '^/my_vhost/(.
)’ to uri ‘/index.php’
[Mon Jun 06 16:52:49.004414 2016] [rewrite:trace1] mod_rewrite.c(468): [rid#7fbe7c324ee0/initial/redir#1] pass through /index.php
[Mon Jun 06 16:52:49.004429 2016] [rewrite:trace3] mod_rewrite.c(468): [rid#7fbe7c324ee0/initial/redir#1] [perdir /var/www/my_vhost/] strip per-dir prefix: /var/www/my_vhost/index.php -> index.php
[Mon Jun 06 16:52:49.004434 2016] [rewrite:trace3] mod_rewrite.c(468): [rid#7fbe7c324ee0/initial/redir#1] [perdir /var/www/my_vhost/] applying pattern ‘^’ to uri ‘index.php’
[Mon Jun 06 16:52:49.004446 2016] [rewrite:trace4] mod_rewrite.c(468): [rid#7fbe7c324ee0/initial/redir#1] [perdir /var/www/my_vhost/] RewriteCond: input=’/var/www/my_vhost/index.php’ pattern=’!-f’ => not-matched
[Mon Jun 06 16:52:49.004451 2016] [rewrite:trace1] mod_rewrite.c(468): [rid#7fbe7c324ee0/initial/redir#1] [perdir /var/www/my_vhost/] pass through /var/www/my_vhost/index.php
[Mon Jun 06 16:52:49.004549 2016] [rewrite:trace2] mod_rewrite.c(468): [rid#7fbe7c323a30/initial/redir#2] init rewrite engine with requested uri /php5-fcgi/index.php
[Mon Jun 06 16:52:49.004556 2016] [rewrite:trace3] mod_rewrite.c(468): [rid#7fbe7c323a30/initial/redir#2] applying pattern ‘^/my_vhost/(.*)’ to uri ‘/php5-fcgi/index.php’
[Mon Jun 06 16:52:49.004561 2016] [rewrite:trace1] mod_rewrite.c(468): [rid#7fbe7c323a30/initial/redir#2] pass through /php5-fcgi/index.php
[Mon Jun 06 16:52:49.004703 2016] [rewrite:trace2] mod_rewrite.c(468): [rid#7fbe7c3100a0/subreq] init rewrite engine with requested uri /index.php
[Mon Jun 06 16:52:49.004710 2016] [rewrite:trace1] mod_rewrite.c(468): [rid#7fbe7c3100a0/subreq] pass through /index.php
[Mon Jun 06 16:52:49.004728 2016] [rewrite:trace3] mod_rewrite.c(468): [rid#7fbe7c3100a0/subreq] [perdir /var/www/my_vhost/] strip per-dir prefix: /var/www/my_vhost/index.php -> index.php
[Mon Jun 06 16:52:49.004735 2016] [rewrite:trace3] mod_rewrite.c(468): [rid#7fbe7c3100a0/subreq] [perdir /var/www/my_vhost/] applying pattern ‘^’ to uri ‘index.php’
[Mon Jun 06 16:52:49.004751 2016] [rewrite:trace4] mod_rewrite.c(468): [rid#7fbe7c3100a0/subreq] [perdir /var/www/my_vhost/] RewriteCond: input=’/var/www/my_vhost/index.php’ pattern=’!-f’ => not-matched
[Mon Jun 06 16:52:49.004757 2016] [rewrite:trace1] mod_rewrite.c(468): [rid#7fbe7c3100a0/subreq] [perdir /var/www/my_vhost/] pass through /var/www/my_vhost/index.php

— apache configuration —

<VirtualHost *:443>

ServerName my_vhost.domain.net
DocumentRoot /var/www/my_vhost
RewriteEngine on
RewriteRule "^/my_vhost/(.*)" "/$1" [NS,PT,E=PATH_INFO:$1]
<Directory /var/www/my_vhost>
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ "index.php" [QSA,L]
  AllowOverride None
  Order allow, deny
  allow from all
</Directory>