fisharebest/webtrees — pull request #63 by IJMacD (2013-12-26 14:05:39+00:00)
Title: Fixed redirection bug

In the case of MOD_REWRITE being used on an Apache server to forge the webtrees url,
webtrees would try to redirect to its source directory path and would not respect
the SERVER_URL site setting (causing an infinite redirect loop).

Further explanation:

Suppose the webtrees source is in a folder named `/webtrees` in the document root of the webserver but suppose you want the URL for your site to be something like `http://example.com/familytree`.

Previously webtrees would not handle this situation correctly and set the `WT_SCRIPT_PATH` constant based on its file path (`/webtrees` from `$_SERVER['SCRIPT_NAME']`). This constant however is used in URL generation e.g. `LOGIN_URL`. It should therefore be calculated from the incoming URL.

The result is all links generated which are based on `WT_SCRIPT_PATH` will take the user to a different URL root; moreover trying to set the `SERVER_URL` site setting in the database causes in infinite redirect loop since Apache tries to redirect to the favoured URL and webtrees sees it does not match the file directory and tries to redirect back.

This commit fixes the bug - if only for the Apache redirect case. I believe this is at least better than no fix at all.