问题
I've been trying to make URLs shorter. For example, change
www.mydomainname.com/myapp/default/mypage
to www.mydomainname.com/mypage
I add the following code in routes.py under the web2py folder:
routes_out=(
('.*:/sevenpeng/default(?P<any>.*)', '\g<any>'),)
But this didn't work. The url still shows www.mydomain.com/default/mypage
Am i missing something?
Another problem, I deployed my website on google appengine, when I typed www.mydomainname.com, it directs to the right page, and the address is still www.mydomainname.com. However, when i typed directly mydomainname.com into browser, the address changes to 1.myapp.appspot.com/myapp. How can I fix this?
Thanks
回答1:
The easiest way to remove the app name and the "default" controller from the URL is to use the parameter-based rewrite system, as follows:
routers = dict(
BASE = dict(
default_application = 'myapp',
default_controller = 'default',
default_function = 'index',
),
)
The above goes in /web2py/routes.py. Note, the parameter-based system cannot be mixed with the pattern-based system.
来源:https://stackoverflow.com/questions/8671936/how-to-make-url-shorter-in-web2py-and-google-appengine