¿How to hide app, controller and function from url?

213 views
Skip to first unread message

Lisandro

unread,
Jul 12, 2014, 8:17:07 AM7/12/14
to web...@googlegroups.com
I'm quite a novice regarding to regular expresions, and I'm stuck with this idea: I want to hide appname, controller and function from specific url, lletting visible only the arguments of the url.

For example, for this url:
http://mydomain.com/init/default/store/erbalito
should look like this
http://mydomain.com/erbalito
where "erbalito" is the first argument of the "store" function inside "default" controller of "init" app.

Is this possible? Could someone help me or point me the way of achieving this? Thanks in advance.

Vinicius Assef

unread,
Jul 12, 2014, 7:55:52 PM7/12/14
to web2py
You can use routes.
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Lisandro Rostagno

unread,
Jul 13, 2014, 9:37:14 AM7/13/14
to web...@googlegroups.com
Thanks for the answer. I should've clarified that I knew that I had to use routes, but I'm having difficult to find the regular expression that works for this case. I suppose I have to use pattern based system, because in addition, I still want to handle "init" as the default application, "default" as the default controller, and "index" as the default function.

This is what I want to achieve:

The public url  should point to  /init/default/index
The public url  /contact  should point to  /init/default/contact
The public url  /erbalito  should point to  /init/default/store/erbalito
The public url  /virtualbike  should point to  /init/default/store/virtualbike
The public url  /robots.txt should point to /init/static/robots.txt

I'm willing to pay some money if someone is able to achieve this consistently. Thanks in advance!



You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/I1W3zXNIcdA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Anthony

unread,
Jul 13, 2014, 10:17:38 AM7/13/14
to web...@googlegroups.com
Use the parameter-based router:

BASE = dict(
    default_application
= 'init',
    default_controller
= 'default',
    default_function
= 'index',
        functions
= ['list', 'of', 'functions', 'in', 'default', 'controller']
)

If you want to exclude the default function in cases where there are URL args, you have to explicitly list the functions in the default controller so web2py can distinguish between args and functions.

Anthony

> For more options, visit https://groups.google.com/d/optout.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/I1W3zXNIcdA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.

Lisandro Rostagno

unread,
Jul 15, 2014, 7:47:51 AM7/15/14
to web...@googlegroups.com
Thanks! It worked. Every day I get even more surprised about web2py features :)
I have though one more doubt. In my case, I put this on routes.py:

BASE = dict(\
  default_application = 'init', \
  default_controller = 'default', \
  default_function = 'store', \
  functions = ['index', 'contact'])

With that, I can achieve what I wanted:
/contact goes to the contact page in /init/default/contact
/erbalito goes to Erbalito's store in /init/default/store/erbalito
/virtualbike goes to VirtualBike's store in /init/default/store/virtualbike

However now, I can only access home page through /index but not through /
¿Is this possible to achieve? ¿Or should I change default_function to "index" and manage there the arg that points me to the store?



To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Anthony

unread,
Jul 15, 2014, 10:02:34 AM7/15/14
to web...@googlegroups.com
However now, I can only access home page through /index but not through /
¿Is this possible to achieve?

You can only have one default function per controller, so for something like that, you would probably need a more complex pattern-based rewrite setup.
 
¿Or should I change default_function to "index" and manage there the arg that points me to the store?

Yes, or if you don't like seeing "index" in the URL, maybe change it to something like "home".

Anthony

Lisandro Rostagno

unread,
Jul 15, 2014, 10:11:10 AM7/15/14
to web...@googlegroups.com
Thank you very much for the help!  I finally decided to keep using parameter-based rewrite setup, as it's easier for me to understand, and it allows me to achieve what I need. 
So I'm using "index" as the default function, that renders the index.html if there is no arg (that is, the home page of my site), and if there is an arg, the function uses the store.html view.
Thanks again!


--
Reply all
Reply to author
Forward
0 new messages