@@ -161,35 +161,41 @@ func (tc *TemplateController) QuestionList(ctx *gin.Context) {
161161}
162162
163163func (tc * TemplateController ) QuestionInfoeRdirect (ctx * gin.Context , siteInfo * schema.TemplateSiteInfoResp , correctTitle bool ) (jump bool , url string ) {
164- id := ctx .Param ("id" )
164+ questionID := ctx .Param ("id" )
165165 title := ctx .Param ("title" )
166+ answerID := uid .DeShortID (title )
166167 titleIsAnswerID := false
167168 needChangeShortID := false
168169
170+ objectType , err := obj .GetObjectTypeStrByObjectID (answerID )
171+ if err == nil && objectType == constant .AnswerObjectType {
172+ titleIsAnswerID = true
173+ }
174+
169175 siteSeo , err := tc .siteInfoService .GetSiteSeo (ctx )
170176 if err != nil {
171177 return false , ""
172178 }
173- isShortID := uid .IsShortID (id )
179+ isShortID := uid .IsShortID (questionID )
174180 if siteSeo .IsShortLink () {
175181 if ! isShortID {
176- id = uid .EnShortID (id )
182+ questionID = uid .EnShortID (questionID )
177183 needChangeShortID = true
178184 }
185+ if titleIsAnswerID {
186+ answerID = uid .EnShortID (answerID )
187+ }
179188 } else {
180189 if isShortID {
181190 needChangeShortID = true
182- id = uid .DeShortID (id )
191+ questionID = uid .DeShortID (questionID )
183192 }
184- }
185-
186- objectType , objectTypeerr := obj .GetObjectTypeStrByObjectID (uid .DeShortID (title ))
187- if objectTypeerr == nil {
188- if objectType == constant .AnswerObjectType {
189- titleIsAnswerID = true
193+ if titleIsAnswerID {
194+ answerID = uid .DeShortID (answerID )
190195 }
191196 }
192- url = fmt .Sprintf ("%s/questions/%s" , siteInfo .General .SiteUrl , id )
197+
198+ url = fmt .Sprintf ("%s/questions/%s" , siteInfo .General .SiteUrl , questionID )
193199 if siteInfo .SiteSeo .PermaLink == constant .PermaLinkQuestionID || siteInfo .SiteSeo .PermaLink == constant .PermaLinkQuestionIDByShortID {
194200 if len (ctx .Request .URL .Query ()) > 0 {
195201 url = fmt .Sprintf ("%s?%s" , url , ctx .Request .URL .RawQuery )
@@ -205,14 +211,14 @@ func (tc *TemplateController) QuestionInfoeRdirect(ctx *gin.Context, siteInfo *s
205211 return true , url
206212 } else {
207213
208- detail , err := tc .templateRenderController .QuestionDetail (ctx , id )
214+ detail , err := tc .templateRenderController .QuestionDetail (ctx , questionID )
209215 if err != nil {
210216 tc .Page404 (ctx )
211217 return
212218 }
213219 url = fmt .Sprintf ("%s/%s" , url , htmltext .UrlTitle (detail .Title ))
214220 if titleIsAnswerID {
215- url = fmt .Sprintf ("%s/%s" , url , title )
221+ url = fmt .Sprintf ("%s/%s" , url , answerID )
216222 }
217223
218224 if len (ctx .Request .URL .Query ()) > 0 {
0 commit comments