diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index 97c17d4661e9f361ae1584ccd41ef2e954649ed2..f8332794f66dd8ebd5e11fbe3cc1834729d51aeb 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -333,6 +333,9 @@ class SimpleSAML_XHTML_Template
         if ($this->translator->getLanguage()->isLanguageRTL()) {
             $this->data['isRTL'] = true;
         }
+
+        // add query parameters, in case we need them in the template
+        $this->data['queryParams'] = $_GET;
     }
 
 
diff --git a/templates/_header.twig b/templates/_header.twig
index 704e340f69c295b42331b5957af347618ce662b1..461dfd25d1b2eacd5ea6d27d908728972f116b59 100644
--- a/templates/_header.twig
+++ b/templates/_header.twig
@@ -5,10 +5,18 @@
 {% if not hideLanguageBar %}
 <div id="languagebar">
     {% for lang in languageBar %}
-
-    {%- if not loop.first -%} | {% endif -%}{% if lang.url %}<a href="{{ lang.url }}">{{ lang.name }}</a>{% else %}{{ lang.name }}{% endif %}
+        {%- if not loop.first -%}|{% endif -%}
+        {% if lang.url %}
+            <a href="{{ lang.url -}}
+            {%- if queryParams %}&{% endif -%}
+            {%- for name, value in queryParams -%}
+                {%- if not loop.first %}&{% endif -%}
+                {%- if value %}{{ name }}={{ value }}{% else %}{{ name }}{% endif -%}
+            {%- endfor %}">{{ lang.name }}</a>
+        {% else %}
+            {{ lang.name }}
+        {% endif %}
 
     {% endfor %}
-
 </div>
 {% endif %}