skip to Main Content

I’m trying to configure redirects on a drupal site using apache web server. I’m trying to implement this https://www.symphonythemes.com/drupal-blog/remove-web-part-composer-based-drupal-site but I cannot seem to get it working. I have several drupal sites running in /var/www/html/drupal. My drupal configuration in my httpd.conf files are

- name: create drupal httpd conf
    copy:
      content: |
               <VirtualHost *:80>
                 ServerName qsd
                 DocumentRoot /var/www/html/drupal
                 <Directory />
                    Options FollowSymlinks
                    AllowOverride All
                 </Directory>
               </VirtualHost>
      dest: /etc/httpd/conf.d/drupal.conf

and

- name: allow override /var/www/html
    copy:
      content: |
                <Directory "/var/www/html">
                  Options Indexes FollowSymLinks
                  AllowOverride All
                  Require all granted
                </Directory>
      dest: /etc/httpd/conf.d/app.conf

I’ve added

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

to my settings.php.

Now I’m trying to get my .htaccess files correct for my drupal app which is in /var/www/html/drupal/app. In /var/www/html/drupal/app/.htaccess I have

<IfModule mod_rewrite.c>
RewriteEngine on
# Redirect to the subdirectory because that's where Drupal is installed
RewriteBase /app
RewriteRule (.*) web/$1 [L]
</IfModule>

In var/www/html/drupal/app/web/.htaccess I have

RewriteBase /web

When I visit https://example.com/app I get redirected to my OIDC provider but the redirect_uri is missing the /app. And when I visit https://example.com/app/user/login I get a 404, but prior to adding .htaccess https://example.com/app/web/user/login was working. Any help would be much appreciated, thank you.

2

Answers


  1. Chosen as BEST ANSWER

    I needed to change var/www/html/drupal/app/web/.htaccess to

    RewriteBase /app/web
    

    and settings.php to

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

    But I think creating a virtual host for each site would allow the original configuration to work as @2pha suggested


  2. I avoid tampering with the server settings or writing redirects when installing Drupal 8+. I make what is called a ‘modified install’. This enables me to stop project initiation mid way to tell Composer where to install Drupal, i.e. to tell Composer what my web-root is, so it doesn’t go ahead to assume it is ‘web/’.

    If you are using shared hosting then most likely your web-root will be ‘public_html’ and if you don’t make a modified install, Composer will assume it is ‘web/’. So I would make a modified install and tell Composer not to install Drupal inside ‘web’ but rather to install inside ‘public_html’.

    I wrote the steps on a blog post, How to install Drupal 9 with Composer on Cpanel. This post is about installing on a cPanel account but the process demonstrates making a modified install, and same principle can be used to install locally or in any folder structure.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search