From 89f6fd65df772f18d6162ff4c805ce3e19d5b86e Mon Sep 17 00:00:00 2001 From: AtaS Date: Tue, 22 Oct 2024 20:24:06 +0100 Subject: [PATCH] 301 redirect when link not found --- SwipetorApp/Controllers/FallbackController.cs | 5 ++- SwipetorApp/Controllers/HomeController.cs | 31 ------------------- 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/SwipetorApp/Controllers/FallbackController.cs b/SwipetorApp/Controllers/FallbackController.cs index 166fd92..557e087 100644 --- a/SwipetorApp/Controllers/FallbackController.cs +++ b/SwipetorApp/Controllers/FallbackController.cs @@ -21,8 +21,7 @@ public IActionResult Index() if (requestPath.StartsWith("/api/", StringComparison.OrdinalIgnoreCase)) return NotFound(); - // If no influencer is found or if the URL does not match any expected patterns, return 404 - Response.StatusCode = 404; - return View("~/Views/Home/Appshell.cshtml", new AppshellViewModel()); + //redirect 301 + return RedirectPermanent("/"); } } diff --git a/SwipetorApp/Controllers/HomeController.cs b/SwipetorApp/Controllers/HomeController.cs index 719aff6..683eea1 100644 --- a/SwipetorApp/Controllers/HomeController.cs +++ b/SwipetorApp/Controllers/HomeController.cs @@ -92,37 +92,6 @@ public IActionResult LoggedOnlyRoutes() return View("Appshell", new AppshellViewModel()); } - - /*[Route("/p/{postId:int}")] - [Route("/p/{postId:int}/{slug}")] - [ProcessLinkRef] - public IActionResult ViewPost(int postId, string slug, int? hubId = null) - { - using var db = dbProvider.Create(); - var post = db.Posts.Include(p => p.User).Include(p => p.Influencer) - .Include(p => p.PostHubs).Include(post => post.Medias).ThenInclude(postMedia => postMedia.PreviewPhoto) - .SingleOrDefault(p => p.Id == postId); - - if (post == null) return RedirectPermanent("/"); - - // Only admins and posters can see a deleted post. - if (post.IsRemoved) return RedirectPermanent("/"); - - if (string.IsNullOrWhiteSpace(slug) || slug.Trim() != post.GetSlug()) - return RedirectPermanent(post.GetRelativeUrl()); - - var desc = !string.IsNullOrWhiteSpace(post.Title) ? post.Title : post.Medias.FirstOrDefault()?.Description; - desc = desc.Shorten(157); - - return View("Appshell", new AppshellViewModel - { - Title = $"{post.Title} by @{post.Influencer?.Name ?? post.User?.Username}", - Description = desc.Trim(), - Image = photoUrlBuilderSvc.GetFullUrl(post.Medias.MinBy(m => m.Ordering)?.PreviewPhoto), - OpenGraphType = OpenGraphType.VideoOther, - Url = $"https://{siteConfig.Value.Hostname}{post.GetRelativeUrl()}" - }); - }*/ [Route("/u/{userId:int}/{userName?}")] public IActionResult UserPage(int userId, string userName)