phil has a blog - Trac redirects to http:// when using SSL

Trac redirects to http:// when using SSL

If you are running behind a HTTP proxy and using SSL you will find that redirects, such as posting a new ticket, will take you to http instead of using https. To fix:

1. Set the base_url in the trac.ini conf, e.g.

base_url = https://www.example.org/trac/projectname/

2.

From version 0.10.5 onwards you can simply add this new line

use_base_url_for_redirect = True

Before 0.10.5 you will need edit api.py to honor the base_url

sudo nano /usr/share/python-support/trac/trac/web/api.py

Inside the redirect function comment out or change..

url = urlparse.urlunparse((self.scheme, urlparse.urlparse(self.base_url)[1], url, None, None, None))

to..

scheme, host, path, params, query, fragment = urlparse.urlparse(self.abs_href())
url = urlparse.urlunparse((scheme, host, url, None, None, None))

Make sure you keep it indented otherwise you will get an “IndentationError: expected an indented block” error and a nasty Internal Server Error in your browser!

You may also want to take a look: Subversion commit failed ‘502 Bad Gateway’ after COPY or MOVE using SSL