AlterEgo
old web2py blog
Useful Links
List all entries
Book
Interactive Examples
F.A.Q.
Free Applications
Plugins
Recipes
Demo of Admin Interface
Semantic web extension
Some of the information here may be outdated, please check the book instead
Edit page
Title:
Security Code:
Body:
(use
this
wiki markup)
web2py supports URL rerwite although this is not really recommended. You should really use Apache (or lighttpd) + mod_proxy (or mod_rewrite) for this purpose. Moreover rewriting web2py urls can break links in applications. So **do not do it**. Anyway if you really really want to ... To use this feature just create a new file in web2py/ called routes.py and write something like this in it routes_in=( ('^127\.0\.0\.1:/testme$','/examples/default/index'), ) routes_out=( ('^/examples/default/index$','/testme'), ) Now visiting `http://127.0.0.1:8000/testme` will result in a call to `http://127.0.0.1:8000/examples/default/index` and this will only work from 127.0.0.1. To the visitor, all links to the page itself will look like links to `/testme` Routes_in consist of a list of 2-tuples. The first element of a tuple is a regular expression of the form '^IP_ADDRESS:PATH$' where IP_ADDRESS is a regex pattern that will match the remote address (".*" to catch them all) and PATH is a regex that matches the path in the requested URL. The second part of the tuple tells web2py how to rewrite the path for those requests that match both the remote address and the path patterns. Notice that "." has to be escaped since it has a special regex meaning. The presence of an IP_ADDRESS pattern allows to rewrite URL differently depending on the remote address IP address and, for example, prevent a certain domain from accessing a certain application. Rules are executed in order. If a request does not match any route in, the url is not rewritten and the request is sent to web2py. Routes_out are used to rewrite the output of the URL(...) function.
© 2008-2010 by Massimo Di Pierro - All rights reserved - Powered by
web2py
- design derived from a theme by
the earlybird
The content of this book is released under the
Artistic License 2.0
- Modified content cannot be reproduced.