简体   繁体   English

在子文件夹中检测到浏览器后重定向

[英]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: 在我的客户网站上,我已通过html元素插入了此脚本:

<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. 现在,这会将用户重定向到另一个index.html,即sfindex.html,该sfindex.html的休憩站点/链接没有应用更平滑的小部件(进一步称为某些功能)。 Means that a Safari User will fallow to a directory called All Sites This Folder do not contain this certain function. 意味着Safari用户将进入名为“所有站点此文件夹”的目录,其中不包含此特定功能。 sf means safari, de means German Language. sf代表野生动物园,de代表德语。

All other browsers continue to the standard Folder. 所有其他浏览器继续使用标准文件夹。 Just /de/ for German 只是/ de /用于德语

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. 如果用户仅从主Web地址开始,那将很好地工作。

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. 我现在要向您寻求帮助的是/ de /文件夹页面中的代码如何将safari用户始终重定向到相应的sf / de /页面。

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. 我尝试使用上面的脚本来实现它,但是我总是失败,因为它将用户重定向到一个不存在的文件夹,例如sf / sf /,这意味着它总是再次添加子文件夹或将其保留在另一个文件夹中组态。

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. 但是htaccess文件中与此有关的问题是,它在Chrome和Opera中不起作用。 It redirects these users as well into the Safari Subfolder /sf/ Any clue to fix that? 它将这些用户也重定向到Safari子文件夹/ sf /中,有任何解决办法?

Thanks very much. 非常感谢。 MacGee 麦基

In the main folder I put into the htaccess file: 在主文件夹中,我放入htaccess文件:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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