@@ -137,10 +137,42 @@ public function add(Request $request): Response
137137 return $ this ->render ('add.twig ' , $ templateVars );
138138 }
139139
140+ /**
141+ * Redirects solution_id URLs to the actual FAQ page
142+ *
143+ * @throws Exception|\Exception
144+ */
145+ #[Route(path: '/solution_id_{solutionId}.html ' , name: 'public.faq.solution ' , methods: ['GET ' ])]
146+ public function solution (Request $ request ): Response
147+ {
148+ $ solutionId = Filter::filterVar ($ request ->attributes ->get ('solutionId ' ), FILTER_VALIDATE_INT , 0 );
149+
150+ if ($ solutionId === 0 ) {
151+ return new Response ('' , Response::HTTP_NOT_FOUND );
152+ }
153+
154+ $ faq = $ this ->container ->get ('phpmyfaq.faq ' );
155+ $ faqData = $ faq ->getIdFromSolutionId ($ solutionId );
156+
157+ if (empty ($ faqData )) {
158+ return new Response ('' , Response::HTTP_NOT_FOUND );
159+ }
160+
161+ // Generate a simple slug from the question title
162+ $ slug = preg_replace ('/[^a-z0-9]+/i ' , '- ' , strtolower ($ faqData ['question ' ] ?? 'faq ' ));
163+ $ slug = trim ($ slug , '- ' ) ?: 'faq ' ;
164+
165+ // Redirect to the canonical FAQ URL
166+ $ url = sprintf ('/faq/%d/%d/%s.html ' , $ faqData ['category_id ' ], $ faqData ['id ' ], $ slug );
167+
168+ return new RedirectResponse ($ url , Response::HTTP_MOVED_PERMANENTLY );
169+ }
170+
140171 /**
141172 * Displays a single FAQ article with comments, ratings, and related content
142173 *
143- * @throws Exception
174+ * @throws Exception|LoaderError*@throws \Exception
175+ *
144176 */
145177 #[Route(path: '/faq/{categoryId}/{faqId}/{slug}.html ' , name: 'public.faq.show ' , methods: ['GET ' ])]
146178 public function show (Request $ request ): Response
@@ -265,7 +297,7 @@ public function show(Request $request): Response
265297 'title ' => sprintf ('%s - %s ' , $ seoData ->getTitle () ?? $ question , $ this ->configuration ->getTitle ()),
266298 'metaDescription ' => $ seoData ->getDescription (),
267299 'solutionId ' => $ faq ->faqRecord ['solution_id ' ],
268- 'solutionIdLink ' => Link:: getSystemRelativeUri () . ' ?solution_id= ' . $ faq ->faqRecord ['solution_id ' ],
300+ 'solutionIdLink ' => ' ./solution_id_ ' . $ faq ->faqRecord ['solution_id ' ] . ' .html ' ,
269301 'breadcrumb ' => $ category ->getPathWithStartpage ($ cat , '/ ' , true ),
270302 'question ' => $ question ,
271303 'answer ' => $ answer ,
0 commit comments