Skip to content

Instantly share code, notes, and snippets.

@masahiko-nitanda
Created October 6, 2023 16:40
Show Gist options
  • Save masahiko-nitanda/9e3279714e9baad2481eece4ee0b95c3 to your computer and use it in GitHub Desktop.
Save masahiko-nitanda/9e3279714e9baad2481eece4ee0b95c3 to your computer and use it in GitHub Desktop.
Go+Revel example for redirecting hyphenated domains to non-hyphenated ones.
package controllers
import (
"github.com/revel/revel"
"strings"
)
type App struct {
*revel.Controller
}
func (c App) Index() revel.Result {
host := c.Request.Host
path := c.Request.URL.Path
if strings.Contains(host, "-") {
newHost := strings.ReplaceAll(host, "-", "")
newURL := "https://" + newHost + path
return c.Redirect(newURL)
}
return c.Render()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment