sub-domain routing to a module

1. about a year ago

petr.pavel
Member
Registered: 2011-06-09
Posts: 394

sub-domain routing to a module

Heya guys,
the website I'm working on has a regular/desktop and a mobile version.

For the regular version, routing is easy because I don't have to care about the domain name.
For the mobile version however, it's different because the domain name is the thing that tells Nette that it should process the request with module MobileModule.

I have a fake tld .pp defined on my workstation to distinguish my development version from the live server. I tried several ways to define routing for the mobile version for both domains but none of them does what I want without some show stopping side effect.

VERSION 1
Here's what I tried:

<?php
// Mobile version
$container->router[] = $mobileRouter = new NRouteList('Mobile');
$mobileRouter[] = new NRoute('//m.example.cz/<action>[/<id>]', 'Page:default');
$mobileRouter[] = new NRoute('//m.example.pp/<action>[/<id>]', 'Page:default');

// Desktop version
$container->router[] = new NRoute('<presenter>/<action>[/<id>]', 'Default:default');
?>

Problem: Redirects m.example.pp to m.example.cz. I want .pp to stay on .pp and .cz to stay on .cz.

VERSION 2
I also tried foo parameters:

<?php
$mobileRouter[] = new NRoute('//m.example.<? pp|cz>/<action>[/<id>]', 'Page:default');
?>

Problem: Redirects to “m.example.”. (no tld at the end, just a dot)

VERSION 3
I tried adding a parameter in place of the tld even though I don't need to use it in my presenter:

<?php
$mobileRouter[] = new NRoute('//m.example.<domain>/<action>[/<id>]', 'Page:default');
?>

Problem: Links contain a presenter name (mobile.page) in their url although this route doesn't contain a placeholder for presenter. I suppose they are in fact made with the desktop version route but I don't understand why. The two previous attempts didn't do that. I want short addresses like m.example.pp/contact-us

Any ideas, guys?

Last edited by petr.pavel (2013-01-11 10:27)


Life is what you make it.

Check & Delete: Bookmarklet pro jednoduché mazání dokumentů z My Kindle Library.

 

2. about a year ago

LeonardoCA
Member
Registered: 2008-06-12
Location: FM
Posts: 236

Re: sub-domain routing to a module

I think to specify presenter separately might help, because presenter is standart part of destination. Try:

$mobileRouter[] = new NRoute('//m.example.<domain>/<action>[/<id>]', array(
'domain' => 'cz',
'presenter' => 'Page',
'action' => 'default'
));

 

3. about a year ago

petr.pavel
Member
Registered: 2011-06-09
Posts: 394

Re: sub-domain routing to a module

It didn't help. Besides, my route already contains a default presenter and action definition: 'Page:default'.

By the way, I cannot specify a default domain because then links lead to the default domain instead of to the current one. Weird but true. With 'domain' => 'cz' I can load home page for m.example.pp (it doesn't redirect) but all links point to m.example.cz.

It's actually kinda funny and I'm beginning to suspect a bug in Nette.
I just noticed that with default domain = cz, the links at .pp do lead to .cz however, at least they don't contain the presenter name!
Upon visiting m.example.pp, a typical link looks like this:
m.example.cz/inventory

When I remove the default domain in order to stay on .pp, the links change to:
m.example.pp/mobile.page/inventory

Interesting, isn't it.

BTW: Nette Framework 2.0.6 (revision 6a33aa6 released on 2012–10–01)


Life is what you make it.

Check & Delete: Bookmarklet pro jednoduché mazání dokumentů z My Kindle Library.

 

4. about a year ago

Schmutzka
Member
Registered: 2010-08-13
Location: Praha, Brno
Posts: 669

Re: sub-domain routing to a module

I've read just the code parts, so sry if I skipped something that had been already said.

This works for me:

$container->router[] = new NRoute('//example.<domain com|ble>/<presenter>/<action>[/<id>]', array(
    'domain' => 'com',
    'presenter' => 'Homepage',
    'action' => 'default'
));

I can load the same content from example.com and example.ble.

This works as well (oh I was so lazy to do that):

$container->router[] = new NRoute('//example.<domain com|ble>/<presenter>/<action>[/<id>]', 'Homepage:default');

 

5. about a year ago

petr.pavel
Member
Registered: 2011-06-09
Posts: 394

Re: sub-domain routing to a module

@Schmutzka: Thanks for the effort but either I missed your point or you didn't bring anything new.

I've already tried using <domain> parameter (my version 3). The only difference in your code was that you listed all possible values (com|ble). I tried that too but it didn't resolve my problem with presenter name in the url.

Perhaps you'll have time later to read the non-code parts as well and test with a route that does not contain a presenter (see my routes in the first post).


Life is what you make it.

Check & Delete: Bookmarklet pro jednoduché mazání dokumentů z My Kindle Library.

 

Board footer

Switch to desktop