#7500 closed defect (wontfix)
Trac href links point to /trac/trac.cgi/foo under mod_rewrite
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | general | Version: | 0.11 |
Severity: | normal | Keywords: | mod_rewrite redirect_url script_url |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description (last modified by )
This seems to be somewhat related to bug #2299…
I've set up Trac 0.11 in CGI mode on a user account on my dedicated server, using a few rewrite rules to make the URLs a little tidier. To speed things up, the static elements are accessed directly instead of accessing them through the CGI.
Now while I can access e.g. http://dev.example.com/trac/myproject/ fine, all the links on the page go via trac.cgi, so the Roadmap ends up linking to http://dev.example.com/trac/myproject/trac.cgi/roadmap instead of http://dev.example.com/trac/myproject/roadmap.
My rewrite rules are as follows:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /trac/trac.cgi/$1 [L,QSA] RewriteRule ^$ /trac/trac.cgi [L]
And the pertinent lines from trac.ini:
[trac] htdocs_location = /trac/static
I've traced the problem down to Trac expecting Apache to set the SCRIPT_URL environment variable, while Apache is actually setting REDIRECT_URL instead.
I've found two solutions to this: 1) Modify trac.cgi to work around the bug This is easy — add these lines just after the comments but before the big try-catch block:
import os if 'SCRIPT_URL' not in os.environ and 'REDIRECT_URL' in os.environ: os.environ['SCRIPT_URL'] = os.environ['REDIRECT_URL']
2) The proper fix. Edit /lib/python*/site-packages/Trac-0.11-py*.egg/trac/web/main.py. Around line 315 you'll see:
script_url = environ.get('SCRIPT_URL') if script_url is not None:
Change this to say:
script_url = environ.get('SCRIPT_URL') if script_url is None: script_url = environ.get('REDIRECT_URL') if script_url is not None:
Note the two lines I added. This makes Trac check for SCRIPT_URL first — if it isn't assigned, then it checks for REDIRECT_URL. This should make it possible for Trac to find out about the mod_rewrite rule and amend the URLs it outputs accordingly.
Attachments (0)
Change History (7)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Description: | modified (diff) |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
CGI is being phased out, as it is very inefficient. So yes, I would recommend to patch your local trac.cgi
.
comment:3 by , 16 years ago
It seems to also happen with mod_wsgi, which is not inefficient. Please reopen if you see fit.
comment:4 by , 15 years ago
This also annoys me with fcgi. Described change to trac source works. Please fix it.
comment:6 by , 12 years ago
Hi. I discovered the following.
If you change .htaccess to
RewriteEngine On SetEnv SCRIPT_NAME "" SetEnv SCRIPT_URL "" RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ trac.fcgi/$1 [L,QSA] RewriteRule ^$ trac.fcgi [L]
then it perfectly works with trac.fcgi.
Can you confirm that?
Michael Mirwaldt
OK, it seems Trac didn't like my formatting… Try again…
1) Modify trac.cgi to work around the bug This is easy — add these lines just after the comments but before the big try-catch block:
2) The proper fix. Edit /lib/python*/site-packages/Trac-0.11-py*.egg/trac/web/main.py. Around line 315 you'll see:
Change this to say:
Note the two lines I added.