title: Why redirect not working?
body: <p>I am trying to log to data base all URL that user type.</p>
  
  <p>After this if the path exists I want to redirect the user to path</p>
  
  <p>Else I want to leave the user in the root directory.</p>
  
  <p><strong>The URL that I type</strong> <code>http://www.mydomain.com/folder1/index.php</code></p>
  
  <p><strong>The output screen</strong></p>
  
  <pre><code>folder1/index.php
  Array ( [0] =&gt; folder1 [1] =&gt; index.php ) url = to folder 1
  folder1/index.php
  </code></pre>
  
  <p><strong>The root directory index.php</strong></p>
  
  <pre><code>&lt;?php
          if ($_GET['url']!= "") {
              // url not empty there is query string
              $url = $_GET['url'];
              $url = rtrim($url, '/');
  
              echo ($url.'&lt;br /&gt;');
              $url = explode('/', $url);
              $file = $url[0];
              print_r($url);
          }
  
          else // url empty it is root directory
              {echo ('&lt;br /&gt; url empty &lt;br /&gt;');}
  
          if ($url[0] == 'folder1'){
              echo ('url = to folder 1&lt;br /&gt;');
              $path = $url[0].'/index.php';
  
              //the path exists do redirect to folder1/index.php
              echo $path ;
                   header( 'Location: http://www.mydomain.com/{$path}' ) ;
          }
  ?&gt;
  </code></pre>
  
  <p><strong>The Htaccess</strong></p>
  
  <pre><code>RewriteEngine on
  Rewritecond %{HTTP_HOST} !^www\.mydomain\.com
  RewriteRule (.*) //www.mydomain.com/$1 [R=301,L]
  RewriteRule \.(sql)$ - [F]
  RewriteRule \.(txt)$ - [F]
  RewriteRule \.(zip)$ - [F]
  RewriteRule \.(rar)$ - [F]
  
  &lt;IfModule mod_rewrite.c&gt;
  # For security reasons, Option followsymlinks cannot be overridden.
  #  Options +FollowSymLinks
     Options +SymLinksIfOwnerMatch
     Options -Indexes
     RewriteEngine On
     RewriteCond %{http_host} ^mydomain.com [NC]
     RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]
     RewriteRule ^([^\.]+)$ index.php?url=$1 [QSA,L,NE]
  &lt;/IfModule&gt;
  
  
  RewriteEngine On
  RewriteCond %{QUERY_STRING} ^(.*)$
  RewriteRule ^(.+)$ index.php?url=$1 [QSA,L,NE]
  </code></pre>
  
  <p>Many thanks</p>