0

I have a website created using Drupal-8 within a sub directory as: /var/www/html/drupal

so http://example.com/drupal is the path used to access the website.

In order to access the website without the sub directory name, I have created a .htaccess with rewrite rule and placed it in the root folder

Then I got the error "User error: Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it"

To solve this, I have included the below code snippet in .settings.php:

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

As my expected domain is at domain.com. Drupal sends the request to itself there, the request is forwarded to Drupal because it's not located where Drupal expects itself to be and as a result fails validation

Now after doing this, I'm able to access the website without using the sub directory name in the URL but the problem is

I'm unable to install or update modules even though I'm logged in as an admin. I see in the logs that the user is identified as "Anonymous" only while trying to install/update module. Before this in the log, there is a log of user identified as "Admin" after logged in.

I've tried clearing the cache, and repairing the session table from the database. commenting out $cookie_domain solved the issue for many who had the same problem in earlier versions of Drupal.

Appreciate any help with this.

  • Are you able to update/remove modules by going to example.com/drupal? – Ash U Mar 29 '17 at 22:47
  • With the rewrite rule : 'RewriteRule (.*) drupal/$1 [L] ' and the code snippet as mentioned above, example.com/drupal is not accessible and the site is accessible only using example.com. Removing this snippet solves the problem of access denial but gives the "redirect URL" error as mentioned above in the question. – Abhi Mar 30 '17 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.