redirects.go 777 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package wrapper
  2. import (
  3. "io/ioutil"
  4. "net/http"
  5. "strings"
  6. )
  7. func (e *Wrapper) redirectToMainDomain() bool {
  8. file, err := ioutil.ReadFile(e.DirVhostHome + "/config/domain")
  9. if err == nil {
  10. maindomain := strings.TrimSpace(string(file))
  11. port := ""
  12. if e.Port != "80" {
  13. port = ":" + e.Port
  14. }
  15. if maindomain+port != e.R.Host {
  16. http.Redirect(*e.W, e.R, e.R.URL.Scheme+"://"+maindomain+
  17. port+e.R.URL.RequestURI(), 301)
  18. return true
  19. }
  20. }
  21. return false
  22. }
  23. func (e *Wrapper) redirectSeoFix() bool {
  24. full := e.R.URL.RequestURI()
  25. uris := full[len(e.R.URL.Path):]
  26. if len(e.R.URL.Path) > 0 {
  27. if e.R.URL.Path[len(e.R.URL.Path)-1] != '/' {
  28. http.Redirect(*e.W, e.R, e.R.URL.Path+"/"+uris, 301)
  29. return true
  30. }
  31. } else {
  32. return false
  33. }
  34. return false
  35. }