You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've run into an issue when using bottle in a subdirectory of the server root.
Steps to reproduce:
Build a simple app in a subdirectory of the server root (CGI works good for that).
Put redirect("/") into a route.
Call the route. You'll be redirected to the server root instead of the application root.
This issue makes it difficult to build apps that are deployed in different paths. The cause of the problem is that redirect() uses urljoin() on the request URL. If the target contains a leading slash, everything after the host part of the URL gets replaced. This could also lead to problems when using mount(), though I haven't tested it yet.
Workarounds:
Build your own redirect function that prepends the application root directory
Add request.script_name to every redirect (ugly)
modify redirect() so that it always includes request.script_name (hackish)
The problem with request.script_name is that in some cases it includes the name of the .py file which would lead to ugly URLs, especially when using CGI on Apache with mod_rewrite. A more sustainable solution would be the introduction of a application root variable (which can be "/" by default). The root path could be set in run() or in a special function. When it is set, all redirects are based on that path.
One could also add the path to SimpleTemplate.defaults to include it in template URLs, but a more beautiful solution for that would be a special markup for URLs (maybe {# #} or similar).
The text was updated successfully, but these errors were encountered:
I've run into an issue when using bottle in a subdirectory of the server root.
Steps to reproduce:
redirect("/")
into a route.This issue makes it difficult to build apps that are deployed in different paths. The cause of the problem is that
redirect()
usesurljoin()
on the request URL. If the target contains a leading slash, everything after the host part of the URL gets replaced. This could also lead to problems when usingmount()
, though I haven't tested it yet.Workarounds:
request.script_name
to every redirect (ugly)redirect()
so that it always includesrequest.script_name
(hackish)The problem with
request.script_name
is that in some cases it includes the name of the .py file which would lead to ugly URLs, especially when using CGI on Apache with mod_rewrite. A more sustainable solution would be the introduction of a application root variable (which can be "/" by default). The root path could be set inrun()
or in a special function. When it is set, all redirects are based on that path.One could also add the path to SimpleTemplate.defaults to include it in template URLs, but a more beautiful solution for that would be a special markup for URLs (maybe
{# #}
or similar).The text was updated successfully, but these errors were encountered: