0

I want access an old site on a new domain. The server and folder remains the same. I have pointed the new domain to the old Drupal site and updated settings.php to include

$base_url = 'http://www.newurl.com';

I can access the site, but all links in the theme and in the control panel point to http://oldurl.com. I can navigate around the site by manually altering each URL to reflect the new domain.

I'm under the impression that updating base_url should work, and take effect immediately. Have I missed something?

2
  • Are the links in a WYSIWYG? Those aren’t dynamic. You need something like drupal.org/project/pathologic to help if they are
    – Clive
    Commented Mar 14, 2018 at 19:13
  • No, it's every link on the site, front-end and back-end.
    – user83960
    Commented Mar 14, 2018 at 19:17

1 Answer 1

0

Seems the website was coded using absolute paths, which is not really good practice from Drupal coding standard's perspective. Please read the discussion on Absolute or relative URLs?. Your case is covered by the accepted answer:

When moving a site from dev > staging > production a Wordpress site's URLs and image references have to be replaced in the DB, this can create an absolute mess.

Though Wordpress is mentioned, that concerns any type of websites, including Drupal.

Anyway, to address the issue you need to do two things:

  1. Look for and replace all the instances of your old domain in the active theme's template folder. This is easier part as any decent text editor has Find&Replace feature.

Check the website again and if everything is working then you are lucky. If not proceed to the second step.

  1. Search and replace all the instances of your old domain in the database tables. You can do it either using drush or UI like phpMyAdmin. The query is pretty simple:

    UPDATE table_name SET field_name = replace(field_name, 'old-domain', 'new-domain');

To do so you first need to figure out the tables where your old domains could be stored. Most probably those are 'node' and 'comment' tables and their last revisions, however if content types have additional custom fields then more tables are involved. You could perform quick search for the old domain in the database to find all the tables where it is stored.

If step 2 is involved, then I would also suggest, using the opportunity, to turn all your paths from absolute to relative. In that case, you would run:

`UPDATE table_name SET field_name = replace(field_name, 'old-domain/', '/');`

instead.

I hope this helps.

9
  • When you say “the website was coded with absolute paths”, what do you mean exactly? OP has mentioned that this is for every link in the site, front and back end, and not just (or even at all) those in a WYSIWYG or link field. I’m struggling to think of how that could have been coded, would you mind elaborating?
    – Clive
    Commented Mar 14, 2018 at 23:34
  • Thanks for your reply. There are two enabled themes - one is the Drupal Seven theme, the other is custom but I can't actually see any files relating to it. I would have thought that even if the theme was badly put together, the back-end links would include the correct domain specified in the configuration? It seems like a global issue - beyond any theming issues.
    – user83960
    Commented Mar 15, 2018 at 9:44
  • @Clive, I meant sometimes they use the absolute paths like http://www.example.com/some-path-to/filename.ext incorporating the website's domain name explicitly instead of using global variable $base_url. And that ends with exactly the same situation as OP reported.
    – AltaGrade
    Commented Mar 15, 2018 at 12:49
  • @user83960, have you actually searched the custom theme's directories for your old domain name? You can do it by changing the working directory to the theme's directory and launch the grep -Ril "old_domain" . command. You should, because if templates contain absolute paths using your old domain, then just specifying the correct domain in the configuration won't help.
    – AltaGrade
    Commented Mar 15, 2018 at 12:51
  • But who’s “they”? Those links are generated by the system, not a person
    – Clive
    Commented Mar 15, 2018 at 12:56

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.