# Get 2 char language code from URL (default to "en") and assign to LANG env var
SetEnvIf ^ ^ LANG=en
SetEnvIf Request_URI "^/([a-z]{2})/" LANG=$1
# Set ErrorDocument dynamically using the language code
# Requires Apache 2.4.13+
# The 2nd argument to the ErrorDocument directive must be prefixed with a slash
# in the source code itself for it to be interpreted as a local path.
ErrorDocument 404 /%{reqenv:LANG}/404/
1条答案
按热度按时间um6iljoc1#
假设语言代码是所请求URL路径的第一个路径段中的两个字符的小写字符串。如果不存在,则默认为
en
。请尝试以下操作:
使用表达式语法生成动态
ErrorDocument
字符串并获取环境变量的值需要Apache 2.4.13+。参考编号: