diff --git a/README.md b/README.md index f992af5..0bd8ad5 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ theme: - netlify ``` -Add redirections: +### Add redirections ```yaml netlify: @@ -29,3 +29,18 @@ netlify: status: 301 # optional force: true # optional ``` + +### Enable redirect by language + +```yaml +netlify: + redirect_by_language: true # false by default +``` + +It generate the following redirect: + +``` +/ /fr/ 302! Language=fr +``` + +> The language can be specified in the cookie `nf_lang`, so you can override the default behavior with JavaScript. diff --git a/layouts/page.netlify_redirects.twig b/layouts/page.netlify_redirects.twig index ba741fc..2342bf4 100644 --- a/layouts/page.netlify_redirects.twig +++ b/layouts/page.netlify_redirects.twig @@ -8,9 +8,9 @@ {{ url(redirect.from, {'canonical': false}) }} {{ url(redirect.to, {'canonical': false}) }}{% if redirect.status is defined %} {{ redirect.status }}{% if redirect.force is defined and redirect.force %}!{% endif %}{% endif ~%} {%- endfor ~%} {%- endif -%} -{#{%- if site.languages > 1 ~%} +{%- if site.netlify.redirect_by_language|default(false) and site.languages > 1 ~%} # Language redirects {%- for language in site.languages|filter(l => l.code != site.language) ~%} / /{{ language.code }}/ 302! Language={{ language.code }} {%- endfor -%} -{%- endif -%}#} \ No newline at end of file +{%- endif -%} \ No newline at end of file