Skip to content

Commit

Permalink
301 redirect when link not found
Browse files Browse the repository at this point in the history
  • Loading branch information
atas committed Oct 22, 2024
1 parent 2f5000f commit 89f6fd6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
5 changes: 2 additions & 3 deletions SwipetorApp/Controllers/FallbackController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("/");
}
}
31 changes: 0 additions & 31 deletions SwipetorApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 89f6fd6

Please sign in to comment.