silverstripe-framework: BASE_URL / Director.alternate_base_url issues & inconsistency
Affects 3.6.3. See also https://github.com/silverstripe/silverstripe-framework/issues/5109.
Issue 1:
Director:
alternate_base_url: 'http://mysite.test'
This results in “Undefined index: path” here: https://github.com/silverstripe/silverstripe-framework/blob/3.6.3/control/Session.php#L358
Adding a trailing slash fixes the issue. I can’t find any documentation for Director.alternate_base_url
which indicates whether or not a trailing slash should be present.
Issue 2:
define('BASE_URL', 'http://mysite.test');
Visiting http://mysite.test?flush
results in a redirection to the wrong URL: http://mysite.test/http:/mysite.test/?flush=&flushtoken=1234
This is because ParameterConfirmationToken
treats the BASE_URL
constant as a relative path, not an absolute URL. BASE_URL
appears to be treated like a relative path in most cases, though the code docs for it suggest that it should be an absolute URL. The code to calculate BASE_PATH
if it’s not defined will also always return a directory name.
Issue 3:
BASE_URL
is used as a fallback for Director.alternate_base_url
when calling Director::baseURL()
, so they should be consistent. Adding a trailing slash to BASE_URL
results in double-slashes in URLs, and removing the trailing slash from Director.alternate_base_url
results in issue 1 above.
Suggested action:
To save a massive refactor to support relative/absolute urls and trailing/non-trailing slashes for both, I’m advocating mostly documentation changes and simple patches.
- Update the code docs for
BASE_URL
to indicate that it should be a relative path to the document root from the domain name (with no trailing slash); - Add documentation for
Director.alternate_base_url
to indicate that a trailing slash should be present; - Bonus round: patch
Director::baseURL()
to force a trailing slash
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 21 (13 by maintainers)
This came up internally again today, I think we need to support it for all config rather than just in injector definitions
Alternate_base_url is a relic intended only for testing to override constants. Maybe since we are using environmental vars now we should encourage this instead of this config.