htaccess的+重定向用户根据不同的浏览器语言

编程入门 行业动态 更新时间:2024-10-26 00:28:14
本文介绍了htaccess的+重定向用户根据不同的浏览器语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在读此主题相关的所有问题,我无法找到任何东西。

首先,我有这样的域名:www.example

我的目的是重定向根据浏览器的语言使用者:

例如:www.example => www.example/es         www.example => www.example/en

我遵循这个规则,但这里不是源网址:

< IfModule mod_rewrite.c> RewriteEngine叙述上 的RewriteCond%{HTTP:接受语言} ^ ES [NC] 的RewriteCond%{HTTP_REFERER}!^ * \。域\ .ar / [NC] 重写规则^ $ www.example/es / [L,R] 的RewriteCond%{HTTP:接受语言} ^ EN [NC] 的RewriteCond%{HTTP_REFERER}!^ * \。域\ .BE / [NC] 重写规则^ $ www.example/en / [L,R] < / IfModule>

解决方案   

在这片code,其中是建立在目标网站?

下面:

重写规则^ $ www.example/es / [L,R]

这里:

重写规则^ $ www.example/en / [L,R]

不知道如果这是一个错字,或者如果这是你在你的htaccess的文件,但是这将产生500内部服务器错误,因为你给重写规则 4个参数,当它只想2或3个

另一个问题是与你的%{HTTP_REFERER} 常规EX pression。 Apache的大概要在这里吐了: ^ * \域\ .ar / ,你可能是指: ^ [^ /] * \。域\ .ar / 什么的。所以,你可能希望你的规则是这样的:

< IfModule mod_rewrite.c> RewriteEngine叙述上 的RewriteCond%{HTTP:接受语言} ^ ES [NC] 的RewriteCond%{HTTP_REFERER}!^ [^ /] * \。域\ .ar / [NC] 重写规则^ $ www.example/es/ [L,R] 的RewriteCond%{HTTP:接受语言} ^ EN [NC] 的RewriteCond%{HTTP_REFERER}!^ [^ /] * \。域\ .BE / [NC] 重写规则^ $ www.example/en/ [L,R] < / IfModule>

当然,你会被更换的情况下, domain.ar 和 domain.be 和 www.example 用正确的主机名。

另外请注意:在接受语言头是预选赛的一个复杂的字符串。它不是那么简单的连接或 ES 。西班牙的web浏览器可以同时包含连接和 ES 仅仅是因为两者都是支持的语言。确定一个确切的语言来重定向到基于这个标题是不是真的在mod_rewrite的和htaccess的范围。

I was reading all questions related to this topic and I couldn't find anything.

First, I have this domain: www.example

My purpose is to redirect users depending on the language of the browser:

ex: www.example => www.example/es www.example => www.example/en

I followed this rule but here is not the source url:

<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP:Accept-Language} ^es [NC] RewriteCond %{HTTP_REFERER} !^*\.domain\.ar/ [NC] RewriteRule ^$ www.example/es / [L,R] RewriteCond %{HTTP:Accept-Language} ^en [NC] RewriteCond %{HTTP_REFERER} !^*\.domain\.be/ [NC] RewriteRule ^$ www.example/en / [L,R] </IfModule>

解决方案

In this piece of code, where is establish the destination website?

Here:

RewriteRule ^$ www.example/es / [L,R]

and here:

RewriteRule ^$ www.example/en / [L,R]

No idea if that's a typo or if this is what you have in your htaccess file, but this will produce 500 internal server errors because you are giving RewriteRule 4 parameters, when it only wants either 2 or 3.

The other problem is with your %{HTTP_REFERER} regular expression. Apache's probably going to puke here: ^*\.domain\.ar/, you probably meant: ^[^/]*\.domain\.ar/ or something. So you probably want your rules to look like this:

<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP:Accept-Language} ^es [NC] RewriteCond %{HTTP_REFERER} !^[^/]*\.domain\.ar/ [NC] RewriteRule ^$ www.example/es/ [L,R] RewriteCond %{HTTP:Accept-Language} ^en [NC] RewriteCond %{HTTP_REFERER} !^[^/]*\.domain\.be/ [NC] RewriteRule ^$ www.example/en/ [L,R] </IfModule>

Of course, you'd be replacing the instances of domain.ar and domain.be and www.example with the correct hostnames.

Also note: the Accept-Language header is a complicated string of qualifiers. It isn't as simple as an en or es. A spanish webbrowser could contain both an en and es simply because both are supported languages. Determining an exact language to redirect to based on this header isn't really in the scope of mod_rewrite and htaccess.

更多推荐

htaccess的+重定向用户根据不同的浏览器语言

本文发布于:2023-10-31 16:39:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546666.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   浏览器   语言   用户   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!