Modules with friendly URLs

69 views
Skip to first unread message

Fregas

unread,
Jan 20, 2011, 4:38:40 PM1/20/11
to Refinery CMS
Hi,

I'm running into an issue with refinery. We have some pages that need
to forward to a custom engine. So we build the engine, set up its
routes and then go into refinery page in the advanced settings and
forward it. Lets say we have a "custom" controller that looks at the
URL and shows some custom content. We then add the forwarding URL to
the Refinery admin:

/custom/index

The problem is we're doing this on a page that in refinery might have
a hierarchy like /products/electronics/mp3/. Refinery changes this
link to point to /custom/index. This makes the URL less SEO
Friendly. We have tinkered with setting up some custom routes so
that /products/electronics/mp3 routes to /custom/index but then if the
user changes the products page title to say "categories" we have to
change all the forwarding pages and our custom routes. Otherwise
links break.

What i'd ideally like is that if we point a refinery page /products/
eletronics/mp3 to a custom controller in an engine like /custom/index,
it would do this "behind the scenes" where the URL wouldn't change but
still execute our custom code without setting up routes that can break
so easily.

Any ideas?

Thanks,
Craig

Philip Arndt

unread,
Jan 20, 2011, 4:40:17 PM1/20/11
to refine...@googlegroups.com
Hey,

So, what you're after, is for the link to not go directly to /custom/index but to bounce through /products/electronics/mp3 first ? Or do you want it to not redirect and "cloak" this somehow (the latter is not as possible).

Phil

Fregas

unread,
Jan 20, 2011, 4:48:33 PM1/20/11
to Refinery CMS
I'd prefer if the link didn't change at all with zero redirect. I
just want the link to the page to stay /products/electronics/mp3 but
for it to execute "custom#index". This is necessory for SEO. Google
and my users shouldn't have to see /custom/index or /mywonderfulmodule/
show just because thats what i named the controller/actions

Philip Arndt

unread,
Jan 20, 2011, 4:51:28 PM1/20/11
to refine...@googlegroups.com
A patch would be very welcome for that functionality. Right now I'm having a hard time visualising how that could be done without it being brittle.
You'd need some sort of dynamic route or magic recall function that was able to figure out which controller was intended and call that instead.

Anybody have any ideas? This would, after all, be very cool.

Fregas

unread,
Jan 20, 2011, 4:54:46 PM1/20/11
to Refinery CMS
So I'm guessing this would require change to the source code? :)

One thing that would eliminate the need for this at all is if Engines
did not normally provide their own routes that a page "Forwarded" to,
but instead acted as widgets that you dropped into one or more page
parts. So if you have a body and a side bar, you could somehow "drop
in" a blog listing in the body and a banner rotator in the right bar.
There was some discussion about this a while back but i'm not sure if
anyone created a branch for it or forked it.

I've seen this done well on a few CMSes.

Philip Arndt

unread,
Jan 20, 2011, 4:59:22 PM1/20/11
to refine...@googlegroups.com
That's not how RefineryCMS works, though, and is unlikely to become the way that RefineryCMS works. The HTML editor is for HTML.. which is why we do the redirect so that you're passing off control to a rails engine rather than trying to do everything in the pages engine.

Fregas

unread,
Jan 20, 2011, 5:03:41 PM1/20/11
to Refinery CMS
I get that, and its fine if that's not really a good place for it.
Although I was thinking that you would choose either a custom engine
OR an HTML editor to place in the page part, not use the HTML editor
to drop in the engine.

Going back to keeping the URLs SEO friendly based on the site
hierarchy, could render_component help for that?

https://github.com/rails/render_component

Philip Arndt

unread,
Jan 20, 2011, 5:05:23 PM1/20/11
to refine...@googlegroups.com
Maybe, but it has some issues: https://github.com/rails/render_component/issues

I think devise does this, I noticed something like it in their source code, maybe that's a good place to start looking?

Fregas

unread,
Jan 20, 2011, 5:08:55 PM1/20/11
to Refinery CMS
Are you the developer on the RefineryCMS?

Philip Arndt

unread,
Jan 20, 2011, 5:10:23 PM1/20/11
to refine...@googlegroups.com

Sven Windisch

unread,
Jan 20, 2011, 5:11:14 PM1/20/11
to Refinery CMS
Hi.

On Jan 20, 10:48 pm, Fregas <fre...@gmail.com> wrote:
> I'd prefer if the link didn't change at all with zero redirect.  I
> just want the link to the page to stay /products/electronics/mp3 but
> for it to execute "custom#index".  This is necessory for SEO.  Google
> and my users shouldn't have to see /custom/index or /mywonderfulmodule/
> show just because thats what i named the controller/actions

You could use a catch-all route. Put this at the bottom of config/
routes.rb with whatever controller and action you want:

map.connect '*path', :controller => '...', :action => '...'

The segments of the route will be available to your controller in the
params[:path] array.

Thus, you catch any route that wasn't caught before and can then
handle it generically.

Cheers,
Sven

Fregas

unread,
Jan 20, 2011, 5:15:04 PM1/20/11
to Refinery CMS
Sven,

This would not prevent Refinery from changing the links of pages in
the nav, in the admin, etc. to "/custom/index".

Craig

Philip Arndt

unread,
Jan 20, 2011, 5:16:35 PM1/20/11
to refine...@googlegroups.com
Currently pages will respond to that route, so in your show action for pages_controller you could bounce it off to some other action, presuming the functionality to do that.

current route:

/*path(.:format) {:controller=>"pages", :action=>"show"}

Then, to change the links you'd have to override our current Page#url method to not use the /custom/index link if the link is relative, i.e. only where links begin with *:// and not / - you must keep external links functioning in the same manner as currently.

Fregas

unread,
Jan 20, 2011, 5:21:01 PM1/20/11
to Refinery CMS
Yeah i was looking at the source for that. Might be a possibility.

What if i have different engines that need to do different things?
How would the catchall route work with multiple engines and multiple
routes?
Reply all
Reply to author
Forward
0 new messages