Allow defining a base URL

Created on 6 February 2025, 2 months ago

Problem/Motivation

The drush user:login command could be in the top 5 most used commands, yet you have to append the domain, like drush user:login -l https://example.org, which gets tiring ...

This is because the base url cannot be set:

$ drush core:status
Drupal version   : 10.4.1                                                    
Site URI         : http://default
[...]

In Drupal 7 it was possible to set the default domain for a Drupal project in settings.php.

See also Drush issue How to define Site URI (default domain) for a Drupal 10 site? #6220.

Suggested solution

Add a new Base URL field on the Basic Site settings (/admin/config/system/site-information) page, allowing the user to set the default domain. If it was added, I guess it could then also be set via settings.php, since it would then be an accessible variable.

User interface changes

Add a new Base URL field under Basic Site settings (/admin/config/system/site-information). This could then also be used by contrib modules, such as XML Sitemap.

Introduced terminology

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

base system

Created by

πŸ‡©πŸ‡°Denmark ressa Copenhagen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ressa
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Add an image.

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    It just dawned on me that "Default front page" shows the actual base URL ...

    I wonder why that variable is not then used in Drush and XML Sitemap ( ✨ Default Base URL Does not export as configuration Active )?

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    My question about "Default front page" was kindly answered by @weitzman on Github:

    'Default front page' is just mirroring back to you the host you are currently using. There is no stored Drupal setting or config for this.

  • Merge request !11139Add base URL to site information β†’ (Open) created by ressa
  • Pipeline finished with Success
    2 months ago
    Total: 385s
    #417195
  • Pipeline finished with Failed
    2 months ago
    Total: 87s
    #417209
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen
  • Pipeline finished with Success
    2 months ago
    Total: 656s
    #417214
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Left some comments in the MR.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 406s
    #434017
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Thanks for the review @smustgrave, it's very much appreciated. Like I wrote, I know very little about writing a test, but am open for any suggestions, to use as a starting point.

    What do you think about the proposal itself?

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Would have to do some research to see why/where it was removed if it existed in D7

    Will dig around the tests though

  • Pipeline finished with Canceled
    about 2 months ago
    Total: 183s
    #434034
  • Pipeline finished with Failed
    about 2 months ago
    Total: 447s
    #434042
  • πŸ‡¬πŸ‡§United Kingdom longwave UK

    ddev manages this without a setting, I don't know how - I assume either an environment variable or something in the settings.php include - but if that's possible I don't see why we need this feature.

    Also, how will this work on sites that listen on multiple domain names?

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    I assume some variable because lando does not.

    I’m a ddev guy just speaking from experience

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    That's true, DDEV takes care of this for local development, and I have updated the Issue Summary to clarify that this feature request is aimed at the web server. It looks like you need to configure this in Lando (https://docs.lando.dev/plugins/drupal/tooling.html#default-url-setup)

    About multiple domain names -- this setting is optional. But I guess this feature could be expanded, maybe via a contrib module to support multisites?

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Adding link in the Issue Summary to the complicated workaround using Direnv: Drush > Set base URL for multiple Drupal installations on server β†’ .

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    @smustgrave: I am still open for a suggestion for a test, to use as a starting point :)

    To give the issue some traction and fresh eyes too give this a look over, and general feedback, I'll change Status, and work on the test, when an example has been suggested.

  • Pipeline finished with Failed
    28 days ago
    Total: 217s
    #454423
  • Pipeline finished with Success
    28 days ago
    Total: 1120s
    #454444
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    I made a simple test.

    @longwave, you asked:

    ddev manages this without a setting, I don't know how - I assume either an environment variable or something in the settings.php include - but if that's possible I don't see why we need this feature.

    So, we got settled that DDEV does this via its Docker settings (see Issue Summary).

    I think the question is, what solution would you or @smustgrave propose to an Ambitious Site Builder with limited Linux skills on shared hosting, maybe even with multiple Drupal installations on the same server, who miss having a base URL?

  • πŸ‡¨πŸ‡­Switzerland znerol

    I'm confused. Is this setting supposed to have any influence on url generation? Like, e.g., on absolute url in emails sent during a cron run? If yes, how would that work with the current implementation? If no, why add it in the first place?

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    I have outlined the usage in the Issue summary, and Drush and XML Sitemap are potential users of this, there are probably others?

  • πŸ‡«πŸ‡·France andypost

    It could be tricky with domain β†’ contrib module and trusted_host_patterns setting

  • πŸ‡¨πŸ‡­Switzerland znerol

    I'd like to avoid the pitfall of wishful/magic thinking here. If drush is supposed to use this feature, then there should be a PoC for drush which demonstrates how this is supposed to be integrated.

    Also if all of the projects mentioned in the issue summary and the comments which are supposed to profit from that feature need to be modified, how do we ensure that this is implemented in a consistent way across the board?

  • πŸ‡¨πŸ‡­Switzerland znerol

    Also please study drush configuration docs, especially the Global options section. If the options.uri is configured, any drush invocation will use that as the default value for --uri. This is useful for sites not running on any of the specialized hosting packages (or ddev).

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Solve in Drush

    I agree about avoiding pitfalls and magical thinking, ideally this would best be solved in Drush in the first place.

    Please see the corresponding Drush issue Document limitation of uri option in non-global drush config file #6220, where I just left a question, about how domains are included in security alert emails. That method might work for getting Site URI as well?

    Feel free to jump in and suggest a solution directly in Drush :)

    Global option -- complicated to set up and limited to a single Drupal instance on server

    Thanks for the link to Global option's, I recently updated that page :) Also, this method only works for a single Drupal installation. The solution for more than one Drupal installation on a server is complex, and requires sudo access (section created by me):

    For a web server with multiple Drupal installations, and the option of installing programs, see Drush > Set base URL for multiple Drupal installations on server β†’ .

    Let's make life easier for Drupal users, who are not Bash experts, and can't install programs

    The reality is this: Many Drupal users have to append the domain, and cannot run simply drush uli, and we should fix this, either in Drupal core or Drush. The workarounds are too complex. Also, mostly you cannot install programs on managed hosting.

    I think we should focus on the use case for the Ambitious Site Builder, and make running Drupal easier, and have updated the Issue Summary, to clarify the end goal.

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen
  • πŸ‡«πŸ‡·France andypost

    I'm sure it must be fixed in drush instead of core, moreover I'm using to provide URL for drush via command line instead of global option specifically for multi-site clients to point which site I'm contacting. Without it drush unable to select proper "sites/domain.tld"

    PS so many efforts put on removal of base_url from core... so please don't wire it again

  • πŸ‡¨πŸ‡­Switzerland znerol

    If you host a single site on a single deployment: Specify options.uri in drush.yml and place that file in one of the following locations sites/all/drush, WEBROOT/drush, or PROJECTROOT/drush. This will be used as the fallback if nothing else is specified (see drush configuration docs - directories and discovery.

    Look into site aliases if you want to do something more complicated. E.g., one site serving multiple domains (example.com, example.org, example.net) or staged deployment (dev, test, staging, production).

    Do not attempt to use environment variables unless you are operating in a containerized environment.

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Thanks for weighing in @andypost -- though it should not be required, only optional, same as for example "Error pages > Default 403 (access denied) page". Also, since it's a config variable, the user can use it from settings.php only, not the GUI.

    Anyway, about solving it in Drush, I agree -- and you should also feel free to join in the Drush issue, and find a permanent solution there:
    https://github.com/drush-ops/drush/issues/6220

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    @znerol: I know there are solutions to this, but they are too complicated, and require deep Bash knowledge. If you have two web sites, the solution becomes extremely complicated.

    Fundamentally, this issue is not about documenting Bash configuration, but finding a solution, so it's not necessary to do it in the first place.

    The Drupal community is shooting itself in the foot, by making solving this simple but reasonable wish way too hard.

    As a user, getting Drush ready should be as easy as running composer require drush/drush and then run drush uli, without doing any Bash configuration.

    If you all agree that Base URL in Drupal is not the right path, can we please try to find a user friendly solution to this in https://github.com/drush-ops/drush/issues/6220?

    I am looking forward to your input :)

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    I have created a fresh Drush issue, dedicated to finding a solution in Drush for this, feel free to share thoughts, MR's, etc.:

    Run drush user:login and automatically have the domain detected #6254

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    @andypost and @znerol, you were correct. It could be solved in Drush, and pretty easily in fact (solution found in Github PR), simply by adding a drush/drush.yml file in each project with this:

    options:
      uri: 'https://example.org'

    The crucial point is, that this solution works well, even if the user has multiple Drupal installations on the same server, for example on a managed web hotel.

Production build 0.71.5 2024