Routing to the main www subdomain for specific controllers

Hi everyone!
I’m using subdomains as user identifiers (username.localhost.com maps to
the profile of that user). However, that complicates things as I do not
want all controllers to work with those subdomains.

Let’s say I have a user controller with a signup action. I do not want
people to be able to go to anything.localhost.com/user/signup, and if
they do I want them to be automatically redirected to
www.localhost.com/user/signup. There would probably be lots of other
controllers/actions I would like that to happen with.

On the other hand, the blog controller index should only displayed when
accesses from a subdomain (username.localhost.com/blog) but not from
www.localhost.com/blog (that would redirect back to the main site).

Question is how can i do this elegantly? Is there a way for me to
automatically redirect to www.localhost.com in certain actions or do I
have to check in the begining of each action if the subdomain is
different the www and then redirect?

Any help would be much appreacited!
Ehud

Check out http://agilewebdevelopment.com/plugins/request_routing

On 04 Apr 2007, at 23:52, Ehud R. wrote:

controllers/actions I would like that to happen with.

Any help would be much appreacited!

Best regards

Peter De Berdt

Peter De Berdt wrote:

Check out http://agilewebdevelopment.com/plugins/request_routing

On 04 Apr 2007, at 23:52, Ehud R. wrote:

controllers/actions I would like that to happen with.

Any help would be much appreacited!

Best regards

Peter De Berdt

Hi Peter,
I’m already using that plugin to allow routing based on subdomains.
The problem is with redirection, not really routing (I think…).

What i’m looking for is a way to redirect a call from
subdomian.localhost.com/controller/action to
www.localhost.com/controller/action - and do it in the simplest way
possible.

Ehud

On Apr 5, 2007, at 1:05 PM, Ehud R. wrote:

subdomian.localhost.com/controller/action to
www.localhost.com/controller/action - and do it in the simplest way

I have a high-priority filter in ApplicationController like this:

Prevents account sites from accessing to the public side. This

filter

assumes the root page is not under public, which is to be

expected, and

redirects there if needed.

def check_access_to_public
if controller_name == ‘public’ && account_subdomain != ‘www’
logger.info(“attempt to access to a public action from an
account site”)
redirect_to_url account_url(account_subdomain)
return false
end
end

It does not do what you want, but that filter depicts a possible
approach.

If your controllers do not mix public and private actions that filter
may suffice. A set of controller names would be used instead of the
hard-coded ‘public’ (my app has all the public stuff served by a
single controller). If there are too many as you suggested in a
previous mail, then you could have abstract controllers
AbstractPublicController, AbstractPrivateController between
ApplicationController and the rest, and test is_a?
(AbstractPublicController).

The redirection would be different as well, but you see the idea.

– fxn