Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirects not working 100% #71

Closed
jonroberts24 opened this issue Sep 8, 2020 · 5 comments
Closed

Redirects not working 100% #71

jonroberts24 opened this issue Sep 8, 2020 · 5 comments
Labels
type/question Further information is requested umbraco/v8 Issues and tasks related to Umbraco 8.

Comments

@jonroberts24
Copy link

When I create a "vanity" redirect, for example /mypage - and redirect it somewhere on the site it works perfectly well.
If I create a redirect from an existing page on the site to redirect somewhere else on the site it doesn't work.

We are using Umbraco 8.6.4 with the latest version of the Skybrud Redirects.

Any ideas?

Thanks Jon

@abjerner abjerner added type/question Further information is requested umbraco/v8 Issues and tasks related to Umbraco 8. labels Sep 8, 2020
@abjerner
Copy link
Member

abjerner commented Sep 8, 2020

Hi @jonroberts24,

If I understand you correctly, the vanity page still exists? The basis of the redirects module is that it only kicks in if nothing at the requested URL exists in Umbraco. So if a page in Umbraco already exists, the redirect will not work.

I hope that answers your question ;)

@jonroberts24
Copy link
Author

jonroberts24 commented Sep 8, 2020

Hi
The Vanity page "mypage" - doesn't exist in the site - its a made up "Short URL".
So, are you saying that the Redirects only works for "Short URLs" or from an old URL that no longer exists to a new url? - not a redirect from one page to another?

@abjerner
Copy link
Member

abjerner commented Sep 8, 2020

@jonroberts24 yes, something like that. But the redirects are not limited to "short URLs" - you can make long URLs like /some/url/you/wish/to/point/to/something/else.

To explain things a bit further, the redirects package works with inbound redirects and outbound redirects.

Inbound redirects are the ones listed in the global dashboard, and you can also add a property editor at the page level to show inbound redirects. Inbound redirects will only work if nothing exists at the specified URL.

This is partially because of performance reasons, as it isn't ideal to hit the database on each request. There is an existing issue for the purpose of introducing forced redirects. The though is that this will work even if a page exists in Umbraco with the same URL. But this is not something I'm actively working on.

Outbound redirects are then instead a redirect from an existing page to somewhere else. The package contains a property editor for this as well:

image

The property editor is only for saving the outbound redirect - there is no logic in the package responsible for redirecting the user from the page with the outbound redirect to it's destination. This should generally be handled somewhere inside the Umbraco request pipeline, but people are likely to handle this very different, which is why the package doesn't handle it for you (for instance, we use Umbraco as a headless CMS, so handling this in the Umbraco request pipeline wouldn't work for us).

@jonroberts24
Copy link
Author

Thank you so much for all your help.
Regarding the Outbound redirects - where, typically, would I put the request pipeline code? In the Global?

@abjerner
Copy link
Member

abjerner commented Sep 8, 2020

When we did Umbraco MVC sites, we'd handle it in the MVC controller (this was in Umbraco 7 though, so the classes are named a bit differently):

using System;
using System.Web.Mvc;
using System.Web.Security;
using Umbraco.Web.Mvc;
using Skybrud.LinkPicker;
using Skybrud.LinkPicker.Extensions;
using Umbraco.Web;

namespace Client.Controllers.Mvc
{
    public class ClientMasterController : RenderMvcController
    {
        protected ViewResult View(Master model)
        {
            return View(null, model);
        }

        protected ViewResult View(string view, Master model)
        {

            try
            {
                LinkPickerItem skyRedirect = model.Content.GetLinkPickerItem("skyRedirect");

                if (skyRedirect != null && skyRedirect.IsValid)
                {
                    Response.Redirect(skyRedirect.Url);
                    return null;
                }
            }
            catch (Exception ex)
            {
                
            }

        }
    }
}

The controllers for each content type would then inherit from this controller, and they would thereby inherit the redirect check. With ModelsBuilder these controllers doesn't make that much sense anymore, so I'm not sure what will be the best location to add that check these days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/question Further information is requested umbraco/v8 Issues and tasks related to Umbraco 8.
Projects
None yet
Development

No branches or pull requests

2 participants