How to access drupal website over web directory

To access Drupal website over web directory,
By using .htaccess.
By setting the docroot.

In public_html/.htaccess (you have to create this file, if it does not exist)

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www.)?yoursitename.com$

RewriteCond %{REQUEST_URI} !^/yoursitename/web/

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

#if you have web folder inside a sub-directory like public_html/subdirectory/web

RewriteRule ^(.*)$ /subdirectory/web/$1

#if no sub-directory

RewriteRule ^(.*)$ /web/$1 RewriteCond %{HTTP_HOST} ^(www.)?yoursitename.com$

#if you have web folder inside a sub-directory like public_html/subdirectory/web

RewriteRule ^(/)?$ subdirectory/web/index.php [L]

#if no sub-directory

RewriteRule ^(/)?$ web/index.php [L]

In settings.php,

Include these lines above DB connection array

if (isset($GLOBALS['request']) && '/{sub_directory_if_any}/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME')) {

$GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');

}

By changing the document root on server(not applicable for shared hosting, since no access)

change documentroot to /home/cpanel_name/public_html/{if_any_sub_directory}/web

Category