How to redirect from others tlds to .com (>

Hi, im doing a web server and i have lots of tlds, .es .uk .asia .it .cc .org

I need to redirect everything even to

(Im using Autocert for Lets Encrypt https certificates)

  1. 301 Redirect in .htaccess
  2. Host these tlds in one place and use the same dns lookup.

We use both methods.


A simple way of doing it in go is to use somekind of middleware function which checks if the requested host is correct and otherwise redirects to the correct host:

package main

import (

func hello(w http.ResponseWriter, r *http.Request) {
	io.WriteString(w, "Hello world")

func redirectOthers(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		if r.Host != "" {
			http.Redirect(w, r, "", 301)
		next.ServeHTTP(w, r)

func main() {
	http.HandleFunc("/", redirectOthers(hello))
	http.ListenAndServe(":80", nil)

to test this put this line in your host file		localhost

And if you try or will it be redirected to

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.