Is is possible to redirect base url '/' to a mounted application at /xyz via config

32 views
Skip to first unread message

ARN NN

unread,
Apr 15, 2020, 3:22:47 PM4/15/20
to cherrypy-users
Hi,

If I have an app mounted at say : '/xyz'
I want that when users invoke url '/' via browser, I want it to redirect to '/xyz'

Is this possible via config  ?
I tried doing it by adding a config section to my app :

[/] 
tools.redirect.on = true
tools.redirect.url = "/xyz"

but this didn't work. Any idea whats wrong and how to fix ?

thanks in advance

Michiel Overtoom

unread,
Apr 16, 2020, 2:57:48 AM4/16/20
to cherryp...@googlegroups.com
Hi,

> On 2020-04-15, at 21:22, ARN NN <arn....@gmail.com> wrote:
>
> Is this possible via config?

I tried your example, but it led to a redirect loop.

I had success with the following code:


#!/usr/bin/env python3

import cherrypy

class Website:
@cherrypy.expose
def index(self):
raise cherrypy.HTTPRedirect("/xyz")

@cherrypy.expose
def xyz(self):
return "Hello from xyz"

if __name__ == "__main__":
cherrypy.quickstart(Website(), "/")



--
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes

Björn Pedersen

unread,
Apr 24, 2020, 6:42:19 AM4/24/20
to cherrypy-users
Best solution for a production instance is to use a suitable frontend  proxy server (e.g. nginx or apache) to handle such things.

Björn
Reply all
Reply to author
Forward
0 new messages