title: How do I set REMOTE_USER in a HTTP header?
body: <p>I've got an issue with my Apache settings. </p>
  
  <p>I installed a web application that partly accepts external authentication:</p>
  
  <ul>
  <li>I use Apache to manage the access to my application web pages.</li>
  <li>If the authentication is successful, the environment variable REMOTE_USER is set with the user's name.</li>
  <li>Then the user name is passed to my application through the HTTP header so the application opens on the user session.</li>
  <li>This is mostly an Apache configuration for the application. I only set the name of the variable (HTTP header) that contains the username in my application config file.</li>
  </ul>
  
  <p>Here is the issue : I can authenticate successfully (most of the time) but my HTTP header is set to null.</p>
  
  <p>Some additional details :</p>
  
  <ul>
  <li>I use Apache and the mod_perl modules (AuthenNIS + AuthzNIS + Net-NIS) to authenticate to my app with NIS account. </li>
  <li><p>With the following Apache config file I have the authentication form  when I try to access my application but the REMOTE_USER header is set to null. </p>
  
  <pre><code>    Listen 2208
      &lt;VirtualHost *:2208&gt;
  
                  RewriteEngine on
                  DocumentRoot "/path/to/static"
  
  
                  &lt;Directory "/path/to/static"&gt;
  
                              Options +Indexes FollowSymLinks MultiViews
                              AllowOverride None
                              Order allow,deny
                              Allow from all
  
  
                              AuthType Basic
                              AuthName "Authentifiez vous"
                              PerlAuthenHandler Apache2::AuthenNIS
                              PerlAuthzHandler Apache2::AuthzNIS
                              PerlSetVar AllowAlternateAuth no
                              require valid-user
  
                  &lt;/Directory&gt;
  
  
                  RewriteEngine on
                  RewriteRule . - [E=RU:%{LA-U:REMOTE_USER}]
                  RequestHeader set REMOTE_USER %{RU}e
  
                         RewriteRule ^/apps$ /apps/ [R]
                         RewriteRule ^/static/style/(.*) /path/to/static/june_2007_style/blue/$1 [L]
                         RewriteRule ^/static/scripts/(.*) /path/to/static/scripts/packed/$1 [L]
                         RewriteRule ^/static/(.*) /path/to/static/$1 [L]
                         RewriteRule ^/favicon.ico /path/to/static/favicon.ico [L]
                         RewriteRule ^/robots.txt /path/to/static/robots.txt [L]
                         RewriteRule ^(.*) http://localhost:2209$1 [P]
  
      &lt;/VirtualHost&gt;
  </code></pre></li>
  </ul>
  
  <p>If I set RequestHeader set REMOTE_USER "username" the application opens on the corresponding user session.</p>
  
  <p>To see the value of REMOTE_USER I use the Firebug Firefox module to display the values of the http header + my application has a script that displays the value of variables passed to it.</p>
  
  <p>I tested an almost identical Apache configuration on an index.php page that displays the values of server variables in a http request. The difference lies in the RewriteRules.</p>
  
  <pre><code>        &lt;?PHP
                      foreach($_SERVER as $key_name =&gt; $key_value) {
                      print $key_name . " = " . $key_value . "&lt;br&gt;";
  
                      }
          ?&gt;
  </code></pre>
  
  <p>In this case, I get a REMOTE_USER et HTTP_REMOTE_USER with a username value.</p>
  
  <p>I don't understand where my problem lies. </p>
  
  <p>Apache 2.2.31
  RedHat 6.5</p>
  
  <p>Thanks in advance !</p>