Locale URL segment being duplicated, eg https://website.test/en/en/ Problem

I have a problem on a local Valet setup: the locale URL segment is appearing twice in URLs.

Eg from a page at URL of en/about/approach, {{ url('about/approach')}} outputs https://website.test/en/en/about/approach

(And you only get the correct URL if outputting this from /about/approach)

Guessing I've missed something obvious but no idea what... thanks!



Setup

Base URLs are set to @web/en/ and @web/de/.

In the web folder we have two index files, eg de/index.php and en/index.php 

Running valet which reports This site is served by [CraftValetDriver].

In general.php I've got:

'test' =&gt; [
// Base site URL
'siteUrl' =&gt; 'http://website.test'


The Entry URI Format for the Pages section is {parent.slug}/{slug}



Contents of /web/en/index.php:

&lt;?php
/**
 * Craft www bootstrap file
 */

// Set path constants
define('CRAFT_BASE_PATH', dirname(__DIR__, 2));
define('CRAFT_SITE', 'english');
define('CRAFT_VENDOR_PATH', CRAFT_BASE_PATH.'/vendor');

$root = dirname(__DIR__).'/en';

// Load Composer's autoloader
require_once CRAFT_VENDOR_PATH.'/autoload.php';

// Load dotenv?
if (file_exists(CRAFT_BASE_PATH.'/.env')) {
    (new Dotenv\Dotenv(CRAFT_BASE_PATH))-&gt;load();
}

// Load and run Craft
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
$app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php';
$app-&gt;run();




Contents of /web/index.php:

&lt;?php
/**
 * Craft web bootstrap file
 */

// Set path constants
define('CRAFT_BASE_PATH', dirname(__DIR__));
define('CRAFT_VENDOR_PATH', CRAFT_BASE_PATH.'/vendor');

// Load Composer's autoloader
require_once CRAFT_VENDOR_PATH.'/autoload.php';

// Load dotenv?
if (file_exists(CRAFT_BASE_PATH.'/.env')) {
    (new Dotenv\Dotenv(CRAFT_BASE_PATH))-&gt;load();
}

// Load and run Craft
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
$app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php';
$app-&gt;run();
Your issue is that the @web alias resolves to this:


  The URL to the folder that contains the index.php file that was loaded for the request


Now that you’re serving your English site from web/en/index.php, @web will already resolve to http://website.test/en.

The alias @web/en you are using for your site’s base URL does therefore resolve to http://website.test/en/en

So you can fix it be using @web for your base URLs, or what I would rather recommend is to serve all your sites from a single web/index.php file (which is possible now in Craft 3). With this change @web will always refer to http://website.test and you need to use @web/en again in your site settings.