简体   繁体   中英

Redirection after browser detection in subfolders

I do have a question about browser detection and redirection to an other Site respectively to an other Folder on the Homepage.

On my clients website I have inserted this script via a html element:

<script>
var ua = navigator.userAgent.toLowerCase(); 
if (ua.indexOf('safari')!=-1){ 
   if(ua.indexOf('chrome')  > -1){
   }else{
   window.location.href = "sfindex.html" // saf
 }
}
</script>

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.

All other browsers continue to the standard Folder. Just /de/ for German

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.

What I'm asking you for help now, is how does the code in the /de/ folder pages need to be, to redirect the safari users always to the corresponding sf/de/ page.

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.

I tried this one as well:

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]

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?

Thanks very much. MacGee

In the main folder I put into the htaccess file:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM