OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.4k stars 2.39k forks source link

Automatic redirection to culture homepage #5089

Open sebastienros opened 4 years ago

sebastienros commented 4 years ago

Maybe we could use a cookie to save the fact that it was the first time on the homepage, and then redirect to the request culture automatically. Not after, as subsequent navigation would be from explicit clicks. The cookie would be short-lived (session) so that the next visit it happens again.

sebastienros commented 4 years ago

Also, there is a custom tag to represent associated languages that is useful for home pages <link rel="alternate" hreflang="fr-FR"/> as see on https://worldnomads.com

Diman96 commented 2 years ago

It is also necessary to make it possible to redirect to the address of the pages that are exposed in the autoroute part to the root of the site of the pages that are the main ones, since it is important for a seo site that there are no duplicate pages.

xperiandri commented 2 years ago

We think that the home page route must redirect (temprorarily) to the content item autoroute URL

Diman96 commented 2 years ago
class HomeRedirectionMiddleware
{
    private readonly RequestDelegate _next;

    private readonly ISiteService _siteService;

    public HomeRedirectionMiddleware(RequestDelegate next, ISiteService siteService)
    {
        _next = next;
        _siteService = siteService;
    }

    public async Task Invoke(HttpContext httpContext)
    {
        var homeRoute = (await _siteService.GetSiteSettingsAsync()).HomeRoute;

        if (httpContext.Request.Path.Equals("/ua", StringComparison.OrdinalIgnoreCase))
        {
            httpContext.Response.StatusCode = 301;
            httpContext.Response.Redirect("/");
        }

        await _next.Invoke(httpContext);
    }
}

@sebastienros how can i get autoroute of homeroute without additional overhead ?

sebastienros commented 2 years ago

@Diman96 there is a service (IAutorouteEntries) that should give you that.