Question

I have Drupal 8.9. When users access the site, they are redirected to their user account page. I want them to be redirected to the home page.

If I leave the Default front page setting empty, the users are redirect to their account page, while the description for the setting says they would be redirected to the home page.

enter image description here

In this field, you must put /node to display the home page.

I know there are modules to do this, but I would like to avoid installing additional modules. Is there a configuration to achieve what I want, in Drupal?

Was it helpful?

Solution

What Drupal considers the default front page is not /node, but /user/login, which redirects logged-in users to their account page. SiteInformationForm::validateForm() contains the following code.

  // Check for empty front page path.
  if ($form_state->isValueEmpty('site_frontpage')) {

    // Set to default "user/login".
    $form_state->setValueForElement($form['front_page']['site_frontpage'], '/user/login');
  }

site_frontpage is the form element for the front page, which in SiteInformationForm::buildForm() is set as follows.

  $front_page = $site_config->get('page.front') != '/user/login' ? $this->aliasManager->getAliasByPath($site_config->get('page.front')) : '';
  $form['front_page']['site_frontpage'] = [
    '#type' => 'textfield',
    '#title' => t('Default front page'),
    '#default_value' => $front_page,
    '#size' => 40,
    '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default front page.'),
    '#field_prefix' => $this->requestContext->getCompleteBaseUrl(),
  ];

Note that the Standard installation profile set the default front page to /node, in its system.site.yml file. Don't take that as the default front page. It's the default value assigned from that installation profile to the Default front page setting.

uuid: ''
name: ''
mail: ''
slogan: ''
page:
  403: ''
  404: ''
  front: /node
admin_compact_mode: false
weight_select_max: 100
langcode: en
default_langcode: en
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top