In shared hosting, the main domain points to /public_html. This default behavior can cause problems if your Drupal installation separates index.php and vendor.
To solve the problem, let's take a practical example.
We have a Drupal installation with the following logic:
- public
- public/web/index.php
- public/vendor/
We compress our public folder and put the public_html folder on the server. Then we dezzip and we have: public_html/public/.
To access the site, write : mon.domaine.com/public/web,
To access the site directly from the domain, we need to :
- Add a .htaccess file to the server root.
RewriteEngine on
# Rediregiger vers un sous parrent.
RewriteCond %{HTTP_HOST} ^(www\.)?mondomaine\.com$
RewriteCond %{REQUEST_URI} !core/authorize.php
RewriteRule !^public/web/ /public/web%{REQUEST_URI} [L]
- Add the following line to the end of settings.php
# Pour la redirection.
if (isset($GLOBALS['request'])) {
if ('/public/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME')) {
$GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');
}
elseif ($GLOBALS['request']->server->get('SCRIPT_URL') === '/core/authorize.php') {
$GLOBALS['request']->server->set('SCRIPT_FILENAME', '/public/web/core/index.php');
}
}
# Vous pouvez également utiliser le chemins absolue complet
if (isset($GLOBALS['request']) and '/public/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME')) {
$GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');
}