diff --git a/cms/templates/login.html b/cms/templates/login.html
index 94fd0f4d95..072e6b9e9b 100644
--- a/cms/templates/login.html
+++ b/cms/templates/login.html
@@ -78,7 +78,7 @@
function(json) {
if(json.success) {
var next = /next=([^&]*)/g.exec(decodeURIComponent(window.location.search));
- if (next.length > 1) {
+ if (next && next.length > 1) {
location.href = next[1];
}
else location.href = "${reverse('homepage')}";