I have installed Drupal 8 on Windows 10 via composer into a directory called fooproject under the htdocs directory.
Scenario 1:
I can access the site using localhost/fooproject/web. When I click the Log in button everything works as expected--generated URL is http://localhost/fooproject/web/user/login. However when I click the logout button, the generated url is localhost/logout and fails with URL was not found. I can logout if I enter localhost/fooproject/web/user/logout.
Scenario 2:
added entry to C:\windows\system32\drivers\etc
127.0.0.1 loc.fooproject.com
added the following to \xampp\apache\conf\extra\httpd-vhosts.conf

DocumentRoot "d:/xampp/htdocs/fooproject/web"
ServerName loc.fooproject.com
ServerAlias loc.fooproject.com.*.xip.io

Entering loc.fooproject.com displays the home page. However, now when I click on Log in, the generated URL is loc.fooproject.com/fooproject/web/user/login which fails. I can log in if I enter
loc.fooproject.com/user/login. After that, when I then click on the Log out button, the log out is successful.

Comments

dibyajyoti.mallick’s picture

Hi,
Please follow the below steps for update your login, logout link:

step 1:

Go to your theme folder and open the your_theme_name.theme file

Put this code in bottom of the page:

function your_theme_name_preprocess_page(&$variables) {
  global $base_url;
  $variables['base_url'] = $base_url;
}

Make sure change your_theme_name on above mention

Step 2:

Go to your template twig file where login and logout link mention

And update the path

Login : {{base_url}}/user/login

logout : {{base_url}}/user/logout

It works all the place, no need to change every time.

Thanks
Dibyajyoti

Prajs’s picture

Thank you for your reply. I completed step 1, but am having trouble trying to figure out where the twig template file for login and logout links is. I am using Bartik. Any suggestions?

flamesquirrel’s picture

Prajs’s picture

I have enabled twig debug and get the following:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'menu__account' -->
<!-- FILE NAME SUGGESTIONS: * menu--account.html.twig x menu.html.twig -->
<!-- BEGIN OUTPUT from 'core/themes/classy/templates/navigation/menu.html.twig' -->
<ul class="clearfix menu">
<li class="menu-item">
<li class="menu-item">
<a href="/user/logout" data-drupal-link-system-path="user/logout">Log out</a>
</li>
</ul>
<!-- END OUTPUT from 'core/themes/classy/templates/navigation/menu.html.twig' -->

menu.html.twig has the following:

     <li{{ item.attributes.addClass(classes) }}>
        {{ link(item.title, item.url) }}
        {% if item.below %}
          {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
        {% endif %}
      </li>

I do not know where to find where item.url is set up.

dibyajyoti.mallick’s picture

Hi,
Put condition :

{% if(item.title  == 'login')%}
{{ link('Login', 'Your coustom path') }}
{% elseif((item.title  == 'log out') %}
{{ link('Log out', 'Your coustom path') }}
{% else %}
{{ link(item.title, item.url) }}
{% endif %}
Prajs’s picture

I appreciate you taking the time to reply to my request.

Your fix works for the login and logout, but I just noticed that "My Account" also references the wrong base_url. It seems odd that if Composer based installation of Drupal is going to be the new thing that there would be any need to change any twig files to address the move of the Drupal code to the web subdirectory.

loopnay66’s picture

I agree and would also appreciate the solution