locomotivecms / engine

A platform to create, publish and edit sites
http://www.locomotivecms.com
Other
2.32k stars 625 forks source link

Feature Request: "Redirect Here From" field on Locomotive::Page #751

Closed benhutton closed 8 years ago

benhutton commented 11 years ago

Hey @did,

I'm working on sites in Locomotive that replace old sites. The URLs are completely changing.

I want a clean way to link an old url with the new page. I don't think using the current page redirect function is even viable - I want to redirect from urls like "index.php?id=123"

What do you think about the following?

1.) Every page has an array of "redirect_here_from_urls" (entered into a textarea in the backend, one per line) 2.) We augment the routing code to query on that field as well. This would involve rewriting the Render.locomotive_page method (https://github.com/locomotivecms/engine/blob/master/lib/locomotive/render.rb#L103-L110), or perhaps something farther up the stack. 3.) If there's a hit, trigger a 301 redirect (or make it configurable 301/302) TO the page that was returned

As always, I'd be happy to implement if this is a desirable feature.

-Ben

HashNotAdam commented 11 years ago

Just my $0.02, I'd love to see redirecting when slugs are changed but I would have thought redirecting from .php style links would be better handled in Nginx/Apache

benhutton commented 11 years ago

There are a couple reasons doing it in Nginx/Apache won't work for me:

1.) I'm using Heroku and so don't have access to those config files 2.) I'm building a multi-tenant site, and each tenant will have their own redirection requirements 3.) I'd like the tenants to be able to configure their own redirects

Beyond that, the main driver would be that Locomotive is trying to let end-users avoid writing actual code, and just work in GUIs and nice templating languages. This would fit with that paradigm, adding some extra power and flexibility.

did commented 11 years ago

hey guys, for better performance, Adam's suggestion is the right way to do but for all the reasons Ben mentioned, I think it would be better to add the custom routes directly in the form of a page. About the implementation, Ben, if you do need it quickly, do the way you described. Otherwise, wait for the new rendering mechanism based on the one used in Wagon (stack of middlewares). Unfortunately, I don't know when I will begin to work on it since we are super focused on making our hosting solution work smoothly. One last thing, if you do need it to assign a 301/302 redirection for each url, do not use a simple array but rather embedded documents (source, redirection_type). Hmmm, would not it be better if we had these redirections (source, target, redirection_type) on the site level instead of page ? Any thoughts ?

benhutton commented 11 years ago

@did i can certainly see some benefits to site-level instead of page-level, but what were you thinking of in particular?

The downsides I see are that you have to specify the target manually, and you have to update the target manually if its slug changes (though we could build in magic that automates this).

@did I do need this kind of soon. Or I have to hack together some alternative. So I'd love to put in the work to build it. If you decide on a model architecture, I can implement that. And then implement the redirect in the controller. Once you move to the middleware stack, it could then be extracted from the controller into a middleware, using the same model setup. What do you think?

greeneca commented 10 years ago

Just to let you guys know Colibri Software has made a plugin to solve this (https://github.com/colibri-software/page_redirect_plugin) if you don't want to use the plugin branch (https://github.com/colibri-software/locomotive_engine/tree/plugins) then you could probably bake this into your app.

did commented 8 years ago

The UI speaks for itself :-)

screen shot 2015-10-22 at 11 16 03 pm
allanbreyes commented 8 years ago

Very nice! :+1: love it.

benhutton commented 8 years ago

@did magical :)