title: Redirection after browser detection in subfolders
body: <p>I do have a question about browser detection and redirection to an other Site respectively to an other Folder on the Homepage.</p>
  
  <p>On my clients website I have inserted this script via a html element: </p>
  
  <pre><code>&lt;script&gt;
  var ua = navigator.userAgent.toLowerCase(); 
  if (ua.indexOf('safari')!=-1){ 
     if(ua.indexOf('chrome')  &gt; -1){
     }else{
     window.location.href = "sfindex.html" // saf
   }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Now, this redirects the user to another index.html namely to the sfindex.html which does not have a smoother widget applied (further called certain function) to its fallowing sites/link. Means that a Safari User will fallow to a directory called
  All Sites This Folder do not contain this certain function. sf means safari, de means German Language.</p>
  
  <p>All other browsers continue to the standard Folder. Just <strong><em>/de/</em></strong> for German</p>
  
  <p>All pages under this folder do have this certain this function enabled.
  So far so good. That works well if the user starts on the main webadress only.</p>
  
  <p>What I'm asking you for help now, is how does the code in the <strong><em>/de/</em></strong> folder pages need to be, to redirect the safari users always to the corresponding <strong><em>sf/de/</em></strong> page.</p>
  
  <p>I tried to use the above script to achieve it, but I failed always, as it would redirect the user to a folder which does not exist for example to sf/sf/ means it always added the subfolder again or left it out in an other configuration.</p>
  
  <p>I tried this one as well:</p>
  
  <pre><code>RewriteEngine on 
  
  # Add /sf/ at the beginning, for safari user
  RewriteCond %{HTTP_USER_AGENT} .*safari [NC]
  RewriteCond %{REQUEST_FILENAME} \.html?$ [NC]
  RewriteCond %{REQUEST_URI} !^/sf/ [NC]
  RewriteRule ^(.*)$ /sf/$1   [R=302,L]
  
  # Delete /sf/ for normal user
  RewriteCond %{HTTP_USER_AGENT} !.*safari [NC]  
  RewriteRule ^sf/(.*)$ /$1   [NC,R=302,L]
  </code></pre>
  
  <p>But the problem with this in the htaccess file is that it does not work in Chrome and Opera. It redirects these users as well into the Safari Subfolder /sf/ Any clue to fix that?</p>
  
  <p>Thanks very much.
  MacGee</p>