Opened 20 years ago
Last modified 8 years ago
#2299 new defect
Ability to override SCRIPT_NAME from base_url
| Reported by: | Owned by: | ||
|---|---|---|---|
| Priority: | normal | Milestone: | unscheduled |
| Component: | general | Version: | 0.11.6 |
| Severity: | normal | Keywords: | review fcgi patch |
| Cc: | CarstenFuchs@…, ethan.jucovy@… | Branch: | |
| Release Notes: | |||
| API Changes: | |||
| Internal Changes: | |||
Description
I am using mod_rewrite to hide the fcgi trac script … this works fine, except that trac uses absolte urls in its generated content … so the name of the fcgi script will be exposed all the same … with this patch I can set the TRAC_BASE_URL environment variable to tell trac what base URL it should be using.
--- temp/trac/trac-0.9/trac/web/cgi_frontend.py 2005-10-31 19:37:51.000000000 +0100 +++ pack/trac-0.9/lib/python2.3/site-packages/trac/web/cgi_frontend.py 2005-11-02 23:30:52.393286000 +0100 @@ -49,6 +49,10 @@ self.args = self._getFieldStorage() self.cgi_location = self.__environ.get('SCRIPT_NAME') + + if 'TRAC_BASE_URL' in os.environ: + self.cgi_location = os.environ['TRAC_BASE_URL']; + self.idx_location = self.cgi_location self.path_info = self.__environ.get('PATH_INFO', '')
Attachments (0)
Change History (23)
comment:1 by , 20 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
comment:2 by , 20 years ago
| Resolution: | worksforme |
|---|---|
| Status: | closed → reopened |
But if one uses RewriteEngine to hide user names in suexec configurations, ScriptAlias does not work. It breaks the suexec mechansim. In such a situation BASE_URL would be a good idea.
comment:4 by , 19 years ago
| Resolution: | → wontfix |
|---|---|
| Status: | reopened → closed |
- the patch is outdated (would need to be updated for 0.10)
- this functionality is available by use of the
base_urloption in trac.ini
comment:5 by , 19 years ago
| Resolution: | wontfix |
|---|---|
| Severity: | minor → normal |
| Status: | closed → reopened |
| Version: | 0.9 → 0.10 |
base_url in trac.ini does not allow to override what SCRIPT_NAME returns … which is necessary when working without ScriptAlias (see above). The following patch adds the necessary functionallity for trac 0.10:
--- trac/web/api.py.orig 2006-09-21 20:32:16.000000000 +0200 +++ trac/web/api.py 2006-10-22 14:00:07.000000000 +0200 @@ -223,7 +223,15 @@ 'has not logged in using HTTP authentication') scheme = property(fget=lambda self: self.environ['wsgi.url_scheme'], doc='The scheme of the request URL') - base_path = property(fget=lambda self: self.environ.get('SCRIPT_NAME', ''), + + def _get_base_url(self): + from urlparse import urlparse + if self.base_url: + return urlparse(self.base_url.encode('latin-1'))[2] + else: + return self.environ.get('SCRIPT_NAME') + + base_path = property(fget=_get_base_url, doc='The root path of the application') server_name = property(fget=lambda self: self.environ['SERVER_NAME'], doc='Name of the server')
comment:6 by , 19 years ago
| Keywords: | fcgi added |
|---|
comment:7 by , 19 years ago
I would like this patch to make it in - it is as far as I can see the only way to make nice URLs with fcgi and mod_rewrite. I am currently manually patching to achieve this aim.
follow-up: 10 comment:8 by , 19 years ago
| Milestone: | → 0.10.4 |
|---|
Could someone familiar with fcgi review this?
comment:9 by , 19 years ago
| Summary: | patch enhancing trac for nice urls → Ability to override SCRIPT_NAME from base_url |
|---|
A slightly related ticket is #2418, which strangely shows up in searches while this one initially didn't.
I run Trac under mod_python and thus can't have this issue (modpython_frontend bails if TRAC_URI_ROOT and base_url don't match), however if this issue still needs fixing I came up with a patch with tests that doesn't reimport urlparse.
comment:10 by , 19 years ago
| Owner: | changed from to |
|---|---|
| Status: | reopened → new |
comment:11 by , 19 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
This has been fixed with r4718:4719 and r4720.
This uses Apache's SCRIPT_URL variable which is specifically intended for reconstructing the logical URL when rewriting has been used, so I think this a cleaner solution.
comment:12 by , 18 years ago
| Component: | general → admin/console |
|---|---|
| Milestone: | 0.10.4 |
| Priority: | normal → highest |
| Severity: | normal → blocker |
| Type: | enhancement → defect |
| Version: | 0.10 |
If you are using Apache mod_rewrite and the script path is still exposed, be aware that the SCRIPT_URL variable is not set by mod_rewrite if the RewriteEngine on directive is used in .htaccess or directory context. SCRIPT_URL is only set if RewriteEngine on is used in the server or VirtualHost context. This is an extremely frustrating issue in mod_rewrite. I thought this worth noting here to hopefully save others some agony in the future. :)
comment:13 by , 18 years ago
| Component: | admin/console → general |
|---|---|
| Milestone: | → 0.10.5 |
| Priority: | highest → normal |
| Severity: | blocker → normal |
| Type: | defect → enhancement |
| Version: | → 0.10 |
Err… it'd be nice if I didn't change all the properties by mistake. I think I just found a Firefox bug. :) Sorry people. I can't change the milestone back to 0.10.4, which is what it should be.
follow-ups: 16 17 comment:15 by , 16 years ago
| Cc: | added |
|---|---|
| Milestone: | 0.10.4 → 0.12 |
| Resolution: | fixed |
| Status: | closed → reopened |
| Type: | enhancement → defect |
| Version: | 0.10 → 0.11.6 |
I have been experiencing the same situation as the ticket reporter, see my mails to the trac-users mailing list.
After long and daunting research I found that James Teh is right in his previous comment and that this ticket addresses the root of the problem and thus should be reopened:
When you use mod_rewrite for pretty Trac URLs as described at TracPrettyUrls, and SCRIPT_URL is not set as described by James Teh, then SCRIPT_NAME is always the rewritten name, which in turn causes "unprettied" or "absolute" URLs in the generated content page.
Work-around: Insert line
os.environ['SCRIPT_NAME'] = ""
into file trac.fcgi.
I'm unfortunately not safe enough in Python in order to know better or even to provide a patch, but wouldn't using REQUEST_URI instead of SCRIPT_NAME help here? Alternatively, please apply the above original patch.
comment:16 by , 16 years ago
Work-around: Insert line os.environSCRIPT_NAME = "" into file trac.fcgi.
The above work-around unfortunately works only for trac.cgi, not for trac.fcgi, sorry.
comment:17 by , 16 years ago
Replying to Carsten Fuchs <CarstenFuchs@…>:
wouldn't using
REQUEST_URIinstead ofSCRIPT_NAMEhelp here?
One problem is that REQUEST_URI is URL-encoded while SCRIPT_NAME and PATH_INFO are not. So in order to find the base of the Trac environment, one would have to strip the query from REQUEST_URI, URL-decode the rest, strip off PATH_INFO, and probably URL-encode the remainder again. So it's not easy, as I learned the hard way in comment:4:ticket:8328.
follow-up: 20 comment:18 by , 16 years ago
| Milestone: | 0.12 → next-major-0.1X |
|---|
We currently don't have a complete solution, and we're a bit short on the testing side for frontends other than mod_python or mod_wsgi. Postponing…
comment:19 by , 15 years ago
| Milestone: | next-major-0.1X → unscheduled |
|---|
comment:20 by , 14 years ago
Replying to rblank:
We currently don't have a complete solution, and we're a bit short on the testing side for frontends other than mod_python or mod_wsgi. Postponing…
If you need volunteers to test patches on mod_fcgi, I can help with that. I'm not familiar enough with the trac codebase to develop a patch myself, but if you gave me pointers I could try to hack something up.
I think a solution to this would be helpful for use in shared hosting environments, where using ScriptAlias or adding anything to the apache config isn't an option, but .htaccess is.
comment:21 by , 13 years ago
| Cc: | added |
|---|
comment:22 by , 10 years ago
| Owner: | removed |
|---|---|
| Status: | reopened → new |
comment:23 by , 10 years ago
| Keywords: | patch added |
|---|



Instead of
mod_rewrite, use aScriptAliascommand to point to the fcgi script and the CGISCRIPT_NAMEvariable will be set appropriately.To run Trac at the root URL: