How to remove subdir from base URL after installing site with Composer on a shared host? I've managed to install drupal 8 using composer and following script:

composer create-project drupal-composer/drupal-project:8.x-dev my_site_name_dir --stability dev --no-interaction

I decided to use composer since it seems to be the new way and you get all the dependencies with it.

But the structure is different then installing drupal by downloading it to the server. And that's my problem.

I'm using shared hosting and before composer everything landed in the folder public_html. But with composer there's a folder called web inside public_html that holds drupal itself (or at least it seems that way to me). So instead of having a url like www.mydomain.com I end up with www.mydomain.com/web to reach the site.

My question is how do I do to hide /web from the url? Or do I do something when installing via composer?

I've done a temporary solution that hides /web just from the frontpage. Had to create a new .htaccess in public_html which included following:

RewriteRule ^$ web/$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /$1 [L] 

But as soon as you click on a different page the /web is there again.

Any hints or of course answers are most welcome.

Thanks //Tobias
Me and my collegue managed to find a working solution.

In our public_html folder we created a .htacess file with the following lines.

RewriteRule ^$ web/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1 [L] 


We edited the .htaccess file in ~user/public_html/web.

# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line: 
RewriteBase /web


In the ~/user/public_html/web/sites/default/settings.php file, we added this code at the bottom.

if (isset($GLOBALS['request']) and
'/web/index.php' === $GLOBALS['request']-&gt;server-&gt;get('SCRIPT_NAME')) {
$GLOBALS['request']-&gt;server-&gt;set('SCRIPT_NAME', '/index.php');
}


We also changed trusted_host_patterns setting as well.

# will allow the site to run off of all variants of example.com and
# example.org, with all the sub-domains included. 

$settings['trusted_host_patterns'] = array(
  '^DOMAIN.com$',
  '^.+.DOMAIN.com$',
  '^DOMAIN.com/web$',
  '^.+.DOMAIN.com/web$',
);


As I said, this is most likely not the correct way to do it, but it worked for us.