internal/redirect: handle go.dev/cl/c/... which keeps popping up

Some shorteners blindly rewrite go-review.googlesource.com/ to go.dev/cl/
but Gerrit has changed the URL schema to start with c/<repo>/+/<id>
instead of just <id>. So we now see URLs like go.dev/cl/c/go/+/12345.
Assume that the leading c/ means it is for Gerrit and redirect accordingly.

Change-Id: I72aa365681145432a6e50eb1ba7b1a85d191a314
Reviewed-on: https://go-review.googlesource.com/c/website/+/447996
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/internal/redirect/redirect.go b/internal/redirect/redirect.go
index 4728064..d701dea 100644
--- a/internal/redirect/redirect.go
+++ b/internal/redirect/redirect.go
@@ -218,6 +218,16 @@
 		return
 	}
 	id := r.URL.Path[len(prefix):]
+
+	// Some shorteners blindly rewrite go-review.googlesource.com/ to go.dev/cl/
+	// but Gerrit has changed the URL schema to start with c/<repo>/+/<id>
+	// instead of just <id>. So we now see URLs like go.dev/cl/c/go/+/12345.
+	// Assume that the leading c/ means it is for Gerrit and blindly redirect.
+	if strings.HasPrefix(id, "c/") {
+		http.Redirect(w, r, "https://go-review.googlesource.com/"+id, http.StatusFound)
+		return
+	}
+
 	// support /cl/152700045/, which is used in commit 0edafefc36.
 	id = strings.TrimSuffix(id, "/")
 	if !validCLID.MatchString(id) {
diff --git a/internal/redirect/redirect_test.go b/internal/redirect/redirect_test.go
index 202554a..7d55bb9 100644
--- a/internal/redirect/redirect_test.go
+++ b/internal/redirect/redirect_test.go
@@ -70,8 +70,10 @@
 		"/cl/267120043":  {302, "https://codereview.appspot.com/267120043"},
 		"/cl/267120043/": {302, "https://codereview.appspot.com/267120043"},
 
-		"/cl/1/3":   {302, "https://go-review.googlesource.com/c/1/3"},
-		"/cl/c/1/3": errorResult(404),
+		"/cl/1/3":      {302, "https://go-review.googlesource.com/c/1/3"},
+		"/cl/blah/1/3": errorResult(404),
+		// /cl/c/ always goes to Gerrit.
+		"/cl/c/anything/at/all": {302, "https://go-review.googlesource.com/c/anything/at/all"},
 
 		// Verify that we're using the Rietveld CL table:
 		"/cl/152046": {302, "https://codereview.appspot.com/152046"},