How does Orchard.Alias handle when aliases change? (SEO/redirect)

Topics: Core, General
Mar 10, 2012 at 4:24 PM

Haven't tried this yet, but wondering what happens when you configure an autoroute part to allow auto updates to an alias. Let's say the user modifies an item's title and this triggers an update to the alias. What happens if the original alias has already been made public and someone tries to access that? Will it result in a  404, or can Orchard.Alias track this to auto forward to the current alias? 

Coordinator
Mar 10, 2012 at 6:53 PM

It will result in a 404 of course, but you can use the RewriteRules module or url rewrites in web.config to set-up a permanent redirect from the old address. Bottomline is that the automatic setting of autoroute is not recommended. Changing a URL after it's gone public is not recommended in general.

Mar 10, 2012 at 7:02 PM

Thanks. I do avoid changing URL's once they are public. I was curious how Orchard would handle if one were to do it. 

Mar 16, 2012 at 3:53 PM

Autoroute will not delete the existing alias. It will add a new one when you update. So the old/new link will be both accessible. You can check the list of aliases using AliasUI

Mar 16, 2012 at 4:18 PM

Thanks for that info. It would be nice if there were a module to add a rel canonical tag for the "current" alias in this case. Or if the Autoroute/Alias modules handled this automatically, but that might be out of scope for core. If it were a separate module you could configure it to either do redirects for the old URL's, or leave them in place and render the canonical meta in the <head> tag. 

Coordinator
Mar 16, 2012 at 5:02 PM

hum ... not sure this is the intended behavior ... Might be a setting on the part.

Jun 18, 2012 at 12:39 PM

@ravetam : You say "Autoroute will not delete the existing alias. It will add a new one when you update."

I'm not seeing this behavior. When I publish a content item all of the aliases for a content item are deleted (apart from the one that matches its Autoroute path). When I change the Autoroute pattern (or the title if "regenerate when editing" is enabled) the alias is just updated, a new one is not created. This includes aliases that have been added manually, they're removed too.

The issue seems to be caused by this method : Orchard.Alias.Implementation.DefaultAliasService.Replace(string, RouteValueDictionary, string)

It seems to make alias functionality redundant if all the other alises are deleted when a content item is published, regardless of whether its title or Autoroute settings were changed.

Jun 18, 2012 at 1:33 PM
Edited Jun 18, 2012 at 1:33 PM

It seems to be related to the discussion we had here : http://orchard.codeplex.com/discussions/358538

I've not opened a bug so far (busy with another project since the instant I wrote this post). Feel free to create one perhaps ?

Jun 18, 2012 at 1:35 PM

Note that my solution will note solve your problem : old aliases will still be deleted. My solution only allows you to create custom aliases which will not be overwritten.

In your case, my code to detect previous versions should be removed and new aliases should only be added.

Jun 19, 2012 at 9:13 AM
gregslater wrote:

@ravetam : You say "Autoroute will not delete the existing alias. It will add a new one when you update."

I'm not seeing this behavior. When I publish a content item all of the aliases for a content item are deleted (apart from the one that matches its Autoroute path). When I change the Autoroute pattern (or the title if "regenerate when editing" is enabled) the alias is just updated, a new one is not created. This includes aliases that have been added manually, they're removed too.

The issue seems to be caused by this method : Orchard.Alias.Implementation.DefaultAliasService.Replace(string, RouteValueDictionary, string)

It seems to make alias functionality redundant if all the other alises are deleted when a content item is published, regardless of whether its title or Autoroute settings were changed.

When i notice this behavior, i'm still using 1.4.0. This is the source for 1.4.0 for the method you mentioned

 

public void Replace(string aliasPath, RouteValueDictionary routeValues, string aliasSource) {
            foreach (var lookup in Lookup(routeValues).Where(path => path != aliasPath)) {
                Delete(lookup);
            }
            Set(aliasPath, routeValues, aliasSource);
        }

 

And this is the new method in 1.4.2

 

public void Replace(string aliasPath, RouteValueDictionary routeValues, string aliasSource) {
            foreach (var lookup in Lookup(routeValues).Skip(1)) {
                Delete(lookup);
            }
            Set(aliasPath, routeValues, aliasSource);
        }

 

Jul 11, 2012 at 11:01 PM

Think those code snippets might be the wrong way around! :)

I've also noticed that the code is different. But even when I changed this method manually to the one in the latest version the behaviour was the same. All aliases for a content item were deleted when it was re-published. It's still deleting the aliases, just not the current one, which is replaced. Before it was replacing aliases, but not the first one, which was incorrect as I'm guessing the first one cannot be assumed to be the current one.