@@ -46,6 +46,9 @@ func (this *IndexAction) RunGet(params struct {
4646 var httpAllDomainMismatchActionCode = serverconfigs .DomainMismatchActionPage
4747 var httpAllDomainMismatchActionContentHTML string
4848 var httpAllDomainMismatchActionStatusCode = "404"
49+
50+ var httpAllDomainMismatchActionRedirectURL = ""
51+
4952 if config .HTTPAll .DomainMismatchAction != nil {
5053 httpAllDomainMismatchActionCode = config .HTTPAll .DomainMismatchAction .Code
5154
@@ -56,6 +59,10 @@ func (this *IndexAction) RunGet(params struct {
5659 if statusCode > 0 {
5760 httpAllDomainMismatchActionStatusCode = types .String (statusCode )
5861 }
62+
63+ if config .HTTPAll .DomainMismatchAction .Code == serverconfigs .DomainMismatchActionRedirect {
64+ httpAllDomainMismatchActionRedirectURL = config .HTTPAll .DomainMismatchAction .Options .GetString ("url" )
65+ }
5966 }
6067 } else {
6168 httpAllDomainMismatchActionContentHTML = `<!DOCTYPE html>
@@ -83,6 +90,8 @@ p { color: grey; }
8390 this .Data ["httpAllDomainMismatchActionContentHTML" ] = httpAllDomainMismatchActionContentHTML
8491 this .Data ["httpAllDomainMismatchActionStatusCode" ] = httpAllDomainMismatchActionStatusCode
8592
93+ this .Data ["httpAllDomainMismatchActionRedirectURL" ] = httpAllDomainMismatchActionRedirectURL
94+
8695 this .Show ()
8796}
8897
@@ -93,6 +102,7 @@ func (this *IndexAction) RunPost(params struct {
93102 HttpAllDomainMismatchActionCode string
94103 HttpAllDomainMismatchActionContentHTML string
95104 HttpAllDomainMismatchActionStatusCode string
105+ HttpAllDomainMismatchActionRedirectURL string
96106 HttpAllAllowMismatchDomainsJSON []byte
97107 HttpAllAllowNodeIP bool
98108 HttpAllDefaultDomain string
@@ -156,11 +166,28 @@ func (this *IndexAction) RunPost(params struct {
156166 var domainMisMatchStatusCode = types .Int (domainMisMatchStatusCodeString )
157167
158168 config .HTTPAll .MatchDomainStrictly = params .HttpAllMatchDomainStrictly
169+
170+ // validate
171+ if config .HTTPAll .MatchDomainStrictly {
172+ // validate redirect
173+ if params .HttpAllDomainMismatchActionCode == serverconfigs .DomainMismatchActionRedirect {
174+ if len (params .HttpAllDomainMismatchActionRedirectURL ) == 0 {
175+ this .FailField ("httpAllDomainMismatchActionRedirectURL" , "请输入跳转目标网址URL" )
176+ return
177+ }
178+ if ! regexp .MustCompile (`(?i)(http|https)://` ).MatchString (params .HttpAllDomainMismatchActionRedirectURL ) {
179+ this .FailField ("httpAllDomainMismatchActionRedirectURL" , "目标网址URL必须以http://或https://开头" )
180+ return
181+ }
182+ }
183+ }
184+
159185 config .HTTPAll .DomainMismatchAction = & serverconfigs.DomainMismatchAction {
160186 Code : params .HttpAllDomainMismatchActionCode ,
161187 Options : maps.Map {
162- "statusCode" : domainMisMatchStatusCode ,
163- "contentHTML" : params .HttpAllDomainMismatchActionContentHTML ,
188+ "statusCode" : domainMisMatchStatusCode , // page
189+ "contentHTML" : params .HttpAllDomainMismatchActionContentHTML , // page
190+ "url" : params .HttpAllDomainMismatchActionRedirectURL , // redirect
164191 },
165192 }
166193
0 commit comments