.htaccess rule for multilingual site

你离开我真会死。 提交于 2019-12-04 07:12:27

You need these additional rules:

# lang supplied in query string
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^lang=([a-z]{2})(?:&|$) [NC]
RewriteRule !^[a-z]{2}/ /%1/%{REQUEST_URI}? [L,NC,R=301]

# lang not supplied in query string
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !^lang=.+(&|$) [NC]
RewriteRule !^en/ /en/%{REQUEST_URI} [L,NC,R=301]

You can redirect your whole site to English as your default or to the correct localized version of your website, with doing something like this:

RewriteRule ^(en|es|de)/(.*)$  $2?lang=$1 [L,QSA]
RewriteRule ^(.*)$  $1?lang=en [L,QSA]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!