Use localeURL middleware with apache prefix
Posted
by Olivier R.
on Stack Overflow
See other posts from Stack Overflow
or by Olivier R.
Published on 2010-06-07T09:37:04Z
Indexed on
2010/06/07
9:42 UTC
Read the original article
Hit count: 405
Good morning everyone,
I Got a question about localeURL usage. Everything works great for me with url like this : www.mysite.com/
- If I type www.mysite.com/ in adress bar, it turns correctly in www.mysite.com/en/ for example.
- If I use the view change_locale, it's also all right (ie change www.mysite.com/en/ in www.mysite.com/fr/).
But my application use apache as server, and use a prefix for the site, that gives url like this : www.mysite.com/prefix/
If I type www.mysite.com/prefix/ in the adress bar, the adress turns into www.mysite.com/en/ without prefix (so 404)
I change code of view to manage our settings.SERVER_PREFIX value :
def change_locale(request) :
""" Redirect to a given url while changing the locale in the path The url and the locale code need to be specified in the request parameters. O. Rochaix; Taken from localeURL view, and tuned to manage : - SERVER_PREFIX from settings.py """ next = request.REQUEST.get('next', None) if not next: next = request.META.get('HTTP_REFERER', None) if not next: next = settings.SERVER_PREFIX + '/' next = urlsplit(next).path prefix = False if settings.SERVER_PREFIX!="" and next.startswith(settings.SERVER_PREFIX) : prefix = True next = "/" + next.lstrip(settings.SERVER_PREFIX) _, path = utils.strip_path (next) if request.method == 'POST': locale = request.POST.get('locale', None) if locale and check_for_language(locale): path = utils.locale_path(path, locale) if prefix : path = settings.SERVER_PREFIX + path response = http.HttpResponseRedirect(path) return response
with this customized view, i'm able to correctly change language, but i'm not sure that's the right way of doing stuff. Is there any option on localeURL to manage prefix of apache ?
© Stack Overflow or respective owner