Apache根据浏览器语言屏蔽访客,做到免插件快速赶走捣乱的访客。
Apache根据浏览器语言屏蔽访客,做到免插件快速赶走捣乱的访客。
Last edited 2022-9-27
type
Post
status
Published
date
Sep 27, 2022
summary
Apache根据语言跳转代码。
tags
干货
category
外贸
slug
Detect_browser_language_and_redirect_to_appropriate_language_version_of_the_website
icon
password
github上有这样一段代码根据语言屏蔽浏览者:
 
Detect browser language and redirect to appropriate language version of the website
 
 
# Redirect visitors who request the root domain path (e.g. www.mywebsite.ch) to the appropriate language version # Fallback to English version if no matching browser language defined # Based on language version being at e.g. www.mywebsite.ch/de/ # This has no effect on any subpaths of the website, and therefore has no effect on e.g. WordPress admin. # Using a 302 temporary redirect header stops the redirection from being cached in the browser. # language is ES-MX (Mexico) RewriteCond %{HTTP:Accept-Language} ^es-mx [NC] RewriteRule ^$ /mx/ [L,R=302] # language is ES-ES (Spain) RewriteCond %{HTTP:Accept-Language} ^es-es [NC] RewriteRule ^$ /es/ [L,R=302] # language starts with DE RewriteCond %{HTTP:Accept-Language} ^de [NC] RewriteRule ^$ /de/ [L,R=302] # language starts with FR RewriteCond %{HTTP:Accept-Language} ^fr [NC] RewriteRule ^$ /fr/ [L,R=302] # language starts with IT RewriteCond %{HTTP:Accept-Language} ^it [NC] RewriteRule ^$ /it/ [L,R=302] # else redirect to the English version RewriteRule ^$ /en/ [L,R=302]
很明显就是根据浏览者的语言判断跳转。改造一下代码,让国内捣乱的同行多关注一下今日头条,而不是我的生意怎么样,这么做:
notion image
  • 干货
  • 欧盟的GDPR和美国的APEC CBPR框架哪个更适合跨境独立站?TouchStone3-10学习笔记:What’s Up?
    Catalog