Created
October 6, 2023 16:40
-
-
Save masahiko-nitanda/9e3279714e9baad2481eece4ee0b95c3 to your computer and use it in GitHub Desktop.
Go+Revel example for redirecting hyphenated domains to non-hyphenated ones.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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