redirects.go 831 B

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