0

I am a sysadmin with some experience in PHP and databases, but a complete Newbie to Drupal.

I have a Drupal site I am hosting but it needed to be moved away from the web root to host a new website altogether. So I moved it from public_html to public_html/archived/. While doing this I updated the htaccess file and drupal's settings.php to make sure references to the root directory / are replaced with /archived/ (including example.com to example.com/archived/. The website loaded but several images and styles were missing. Inspecting the rendered HTML showed that all the style attributes in different tags got prepended by /archived/. So something like:

<div style="width:100%"> became <div style="/archived/width:100%">

I have never seen this kind of behavior. And I am not sure if this was because of the changes in htaccess or settings.php, or if there is some theme level code doing this.

Just to try my luck, I moved the website from /public_html/archived to /archived/ and pointed a subdomain archived.example.com to it. I updated htaccess and settings.php again. The same issue happened with the style attribute

<div style="/width:100%">

Here are the changes I am doing in .htaccess

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://archived.example.com/$1 [L,R=301]

RewriteBase /

And here is what I am updating in /sites/default/settings.php

$settings['trusted_host_patterns'] = [
   '^archived\.example\.com$'
];

There is also this in settings.php

$settings['file_public_base_url'] = 'https://archived.example.com/';

But I have commented it out right now.

5
  • 2
    There’s nothing in Drupal core that would do this, check the functionality of contrib and custom modules/themes, the culprit will probably be in there somewhere. Change the front end theme and see if the problem persists, start uninstalling modules one by one until you see a difference, that kind of thing
    – Clive
    Jan 29 at 17:54
  • Are you sure this is the real source code and not some kind of "browser dev tools tries to fix broken HTML attributes / missing closing quotes" source code?
    – Hudri
    Jan 29 at 21:18
  • Ctrl+U for real source code
    – Hudri
    Jan 29 at 21:39
  • @Clive yes there is a custom theme, will look into that thanks. Jan 30 at 18:43
  • @Hudri I can see this in the source as well. And from that I also noticed that this is happening to all HTML attributes (so in id, class too) in most (not all) pages. So weird. Jan 30 at 18:45

1 Answer 1

0

While doing this I updated the htaccess file and drupal's settings.php to make sure references to the root directory

There is nothing to do in these files or others to change the directory from where Drupal runs. Just move the files, adjust the web server's vHost config, and clear the cache. The recommended composer project contains a web subfolder, for security reasons you should only publish this subfolder and not the composer root directory.

If the style attributes get overridden, this is not normal Drupal behavior, as @Clive mentioned. This is probably a previous attempt to manipulate the directory from where Drupal runs.

2
  • In the htaccess file I found the following comment: # 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 /drupal # # If your site is running in a VirtualDocumentRoot at http://example.com/, # uncomment the following line: RewriteBase / Hence the edits I made Jan 30 at 18:48
  • When running in a subdirectory Drupal detects this automatically and adjusts the base path. When clearing the cache all paths are recalculated and everything should be OK. No need to set RewriteBase, at least not for Drupal since version 8.
    – 4uk4
    Jan 30 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.