title: php variables not interpreted during rewrites
body: <p>I've been tasked with helping provide the infrastructure for an external facing website and things are mostly fine, it's deployed and puppet control and hooray for my standards etc.</p>
  
  <p>However, it gets tricky because we are provided the code for the website by an external developer and they quickly noticed that 'rewrites are not working'
  I spent some time checking into this and rewrites for apache using an .htaccess file are indeed working perfectly.
  Where it falls down is that php variables are not being passed or interpreted during a rewrite operation
  I posted a previous stackoverflow question with extremely detailed info and have since then simplified down my example considerably. </p>
  
  <p><a href="https://stackoverflow.com/questions/35064085/my-mod-rewrite-rules-do-not-resolve-php-variables">My mod_rewrite rules do not resolve PHP variables</a></p>
  
  <p>nobody was able to determine the issue in my previous thread, so I've simplified my case somewhat for testing. </p>
  
  <p>my basic troubleshooting .htaccess file is here</p>
  
  <pre><code>&lt;ifModule mod_rewrite.c&gt;
  RewriteEngine on
  RewriteRule ^test/test2/$ test.php?var=test2&amp;var2=test [L]
  RewriteRule ^hello.html redir.html [L]
  &lt;/ifModule&gt;
  &lt;IfModule mod_security.c&gt;
  SecFilterEngine Off
  SecFilterScanPOST Off
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>and when accessing
  <a href="http://server.example.net/hello.html" rel="nofollow noreferrer">http://server.example.net/hello.html</a>
  I'm correctly taken to my redir.html page. So I know rewrites work and I checked that by tailing the log file to confirm as well.
  Now the problem, when I run my the following</p>
  
  <p><a href="http://server.example.net/test/test2/" rel="nofollow noreferrer">http://server.example.net/test/test2/</a></p>
  
  <p>it should redirect to my test.php file</p>
  
  <p>http-//server.example.net/test.php?var=test2&amp;var2=test which is a really basic file</p>
  
  <pre><code>&lt;?php
  echo $_GET['var'].'aa'.$_GET['var2'];
  ?&gt;
  </code></pre>
  
  <p>now if I browse to the location without using rewrites I get the html page as follows</p>
  
  <pre><code>test2aatest
  </code></pre>
  
  <p>which shows the 2 variables being parsed and displayed on the page. But if I visit with the url that uses rewrites</p>
  
  <p>http-//server.example.net/test/test2/</p>
  
  <p>then I get the following</p>
  
  <pre><code>Notice: Undefined index: var in /var/www/itnews/test.php on line 4
  Notice: Undefined index: var2 in /var/www/itnews/test.php on line 4
  aa
  </code></pre>
  
  <p>which tells me that I am correctly redirected to the page, but there is something wrong with the variables.
  If it helps
  OS - Centos 7 x64 and all latest updates</p>
  
  <pre><code>php packages
  php.x86_64                       5.4.16-36.el7_1                       @base
  php-cli.x86_64                   5.4.16-36.el7_1                       @base
  php-common.x86_64                5.4.16-36.el7_1                       @base
  php-gd.x86_64                    5.4.16-36.el7_1                       @base
  php-mbstring.x86_64              5.4.16-36.el7_1                       @base
  php-mysql.x86_64                 5.4.16-36.el7_1                       @base
  php-pdo.x86_64                   5.4.16-36.el7_1                       @base
  php-snmp.x86_64                  5.4.16-36.el7_1                       @base
  </code></pre>
  
  <p>apache</p>
  
  <pre><code>httpd.x86_64                     2.4.6-40.el7.centos                   @base
  httpd-tools.x86_64               2.4.6-40.el7.centos                   @base
  </code></pre>
  
  <p>lastly, my rewrite log.</p>
  
  <pre><code>[Mon Feb 22 13:10:16.901115 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffef2d0/subreq] [perdir /var/www/itnews/] add path info postfix: /var/www/itnews/test.php -&gt; /var/www/itnews/test.php/test2/
  [Mon Feb 22 13:10:16.901131 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffef2d0/subreq] [perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/test.php/test2/ -&gt; test.php/test2/
  [Mon Feb 22 13:10:16.901135 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffef2d0/subreq] [perdir /var/www/itnews/] applying pattern '^test/test2/$' to uri 'test.php/test2/'
  [Mon Feb 22 13:10:16.901140 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffef2d0/subreq] [perdir /var/www/itnews/] add path info postfix: /var/www/itnews/test.php -&gt; /var/www/itnews/test.php/test2/
  [Mon Feb 22 13:10:16.901144 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffef2d0/subreq] [perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/test.php/test2/ -&gt; test.php/test2/
  [Mon Feb 22 13:10:16.901147 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffef2d0/subreq] [perdir /var/www/itnews/] applying pattern '^hello.html' to uri 'test.php/test2/'
  [Mon Feb 22 13:10:16.901156 2016] [rewrite:trace1] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffef2d0/subreq] [perdir /var/www/itnews/] pass through /var/www/itnews/test.php
  [Mon Feb 22 13:10:16.901241 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffdd240/initial] [perdir /var/www/itnews/] add path info postfix: /var/www/itnews/test.php -&gt; /var/www/itnews/test.php/test2/
  [Mon Feb 22 13:10:16.901251 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffdd240/initial] [perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/test.php/test2/ -&gt; test.php/test2/
  [Mon Feb 22 13:10:16.901255 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffdd240/initial] [perdir /var/www/itnews/] applying pattern '^test/test2/$' to uri 'test.php/test2/'
  [Mon Feb 22 13:10:16.901274 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffdd240/initial] [perdir /var/www/itnews/] add path info postfix: /var/www/itnews/test.php -&gt; /var/www/itnews/test.php/test2/
  [Mon Feb 22 13:10:16.901279 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffdd240/initial] [perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/test.php/test2/ -&gt; test.php/test2/
  [Mon Feb 22 13:10:16.901282 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffdd240/initial] [perdir /var/www/itnews/] applying pattern '^hello.html' to uri 'test.php/test2/'
  [Mon Feb 22 13:10:16.901286 2016] [rewrite:trace1] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffdd240/initial] [perdir /var/www/itnews/] pass through /var/www/itnews/test.php
  [Mon Feb 22 13:10:16.901375 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffe7290/subreq] [perdir /var/www/itnews/] add path info postfix: /var/www/itnews/test2 -&gt; /var/www/itnews/test2/
  [Mon Feb 22 13:10:16.901387 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffe7290/subreq] [perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/test2/ -&gt; test2/
  [Mon Feb 22 13:10:16.901391 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffe7290/subreq] [perdir /var/www/itnews/] applying pattern '^test/test2/$' to uri 'test2/'
  [Mon Feb 22 13:10:16.901395 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffe7290/subreq] [perdir /var/www/itnews/] add path info postfix: /var/www/itnews/test2 -&gt; /var/www/itnews/test2/
  [Mon Feb 22 13:10:16.901401 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffe7290/subreq] [perdir /var/www/itnews/] strip per-dir prefix: /var/www/itnews/test2/ -&gt; test2/
  [Mon Feb 22 13:10:16.901405 2016] [rewrite:trace3] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffe7290/subreq] [perdir /var/www/itnews/] applying pattern '^hello.html' to uri 'test2/'
  [Mon Feb 22 13:10:16.901408 2016] [rewrite:trace1] [pid 29768] mod_rewrite.c(468): [client 192.168.0.55:65280] 192.168.0.55 - - [server.example.net/sid#7f8f6fceb9c0][rid#7f8f6ffe7290/subreq] [perdir /var/www/itnews/] pass through /var/www/itnews/test2
  </code></pre>
  
  <p>note, I'm in ops and I'm not familiar with php so I'm working on second hand info about how php works exactly.</p>