I defined:

$base_url = '';

in my settings.php file, which had the desired effect of generating relative URLs for all my local files.

But the system complained when I upgraded my Backdrop core version: a required database update failed with a "page not found" message.

The reason was because in the file:

core/includes/bootstrap.inc

on line 898, the test for a base URL tests just for the existence of the $base_url variable. If the line:

if (isset($base_url)) {

was replaced by:

if (! empty($base_url)) {

then my problem would be solved.

Comments

klonos's picture

Hello ,

I am sorry that this has caused you problems. It seems though that you have already found a workaround/solution, so I'm glad things worked out in the end.

Thanks for taking the time to report both the issue itself, as well as the possible solution; can you please also take the time to report this in more detail in our issue queue in https://github.com/backdrop/backdrop-issues/issues.

I would like you to please elaborate more on things like:

  • the reason you had to manually specify base_url in your settings.php (what was not working, what was special with your setup, etc.)
  • which version of Backdrop did you try to upgrade to (and from which version), and which database update it was that errored on you?

I would really like this to not be an issue for others, so we need a way to be able to reproduce it, so that we can then fix it.

Thanks again :)

I don't think $base_url was designed to be forced to be blank. I think it's used to provide another level of security by reducing spoofing.

I would recommend trying to find a different way of accomplishing your goal (you could give an example of your URLs before and after here).

Thank you for your comments.

The reason I specified $base_url as an empty string was so that URLs referring to files on the web server would be generated as relative URLs. The reason I wanted to do that is so that the web site would still work if it was migrated to a different server (like web.archive.org).

An example of my URLs before and after is:

<script src="https://www.example.com/files/js/js_mswEteo3gQZ23cCRV4ouvfxXuIxX4zLVmI-3pYYarTM.js"></script>

without defining $base_url as empty, and:

<script src="/files/js/js_mswEteo3gQZ23cCRV4ouvfxXuIxX4zLVmI-3pYYarTM.js"></script>

with $base_url = ''; in the settings.php file.

My database update problem occurred when I updated the Backdrop version from 1.13.4 to 1.14.1.

I realise that I have abused the $base_url variable but I couldn't see a simple alternative way of achieving the same result.