Shahms King wrote: > I agree that messing with SCRIPT_NAME and PATH_INFO is unpleasant and > I'd like a better solution, I'm just not sure one is possible given > current mod_python and Apache. Attached are my functions for deriving from REQUEST_URI. They seem simple enough, but perhaps the output is different than what you need. -John -- http://giftfile.org/ :: giftfile project
def get_script_name(request): """Return script name as given in original URI The SCRIPT_NAME CGI variable becomes useless when URL rewriting is used, because it contains the script name resulting from the server's internal redirect. As a workaround, this function makes use of a CGI variable called REQUEST_URI to compute the real requested script name. REQUEST_URI is not part of CGI/1.1, so if it doesn't exist we fall back to SCRIPT_NAME. The script name is formed by removing the path info and optional query from the tail of the request URI. So given "http://example.net/script/foo?bar", we have: REQUEST_URI /script/foo?bar PATH_INFO /foo QUERY_STRING bar and the result will be "/script". """ request_uri = request.get_header('REQUEST_URI') if request_uri: path_info = request.get_header('PATH_INFO') query_string = request.get_header('QUERY_STRING') if query_string == '': tail = path_info else: tail = '%s?%s' % (path_info, query_string) return request_uri[:-len(tail)] else: return request.get_header('SCRIPT_NAME') def get_path(request): """Return path as given in original URI""" request_uri = request.get_header('REQUEST_URI') if request_uri: query_string = request.get_header('QUERY_STRING') if query_string == '': return request_uri else: return request_uri[:-(len(query_string)+1)] else: return request.get_path()