TL;DR Filepaths contain old subdomain prefix after find replace database and site code, can't determine cause.

I have a hosted site on mywebsite.com/drupal, I want to move it to my computer localhost.

I have a LAMP stack and I compress and download the contents of mywebsite.com/drupal and export its mysql database, mydb.sql, using phpmyadmin.

I uncompress and place all the files from mywebsite.com/drupal in /var/www/html/, I create a new database, local.db, locally and import mydb.sql. I edit /var/www/html/sites/default/settings.php $databases array and connect it to local.db.

I ensure all files permissions are correct by running

chown user:user -R /var/www/html/
chmod -R 755 /var/www/html/

I can then access my site using a browser and going to localhost, however the images are missing none of the links work.

Initially I thought the cause was that there are many instances in the database and my site code still containing filepaths with the subdomain /drupal/ prefix, images for example:


When I move the site to localhost, it should just be:


To solve this, I did a find /drupal/ and replace / in my database, reimported it and then used grep -rl '/drupal/' ./ | xargs sed -i 's_/drupal/_/_g' on /var/www/html/.

I thought this would have resolved the problem, however when I access localhost, the problem persists, images and links still contain the /drupal/ prefix in their filepaths. I've read on a few migration guides that I should flush all caches on the drupal backend before moving (which I did) and also potentially flush the mysql cache using phpmyadmin, however I get an error #1146 - Table 'mydb.cache' doesn't exist when I try to execute the truncate commands.

Other guides mention .htaccess, which I copied over from mysite.com/drupal, admittedly I don't understand everything inside it deeply, but I can't find any code which is prefixing filepaths with /drupal/.

As a sanity check, I created /var/www/html/drupal/ and copied my site and then everything works fine.

I don't understand, how can the filepaths remain the same when I have changed all instances in the database and site code? I think there is something easy I'm missing but I can't figure it out.

1 Answer 1


Is this Drupal 7 or 8? Not sure that it matters, but take a look at around line 102 of your .htaccess file, should look like this:

# 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

The issue you describes sounds like the RewriteBase is incorrect. What does your .htaccess say?

Can you also tell me what your settings.php file has for the base URL value?

# $base_url = 'http://www.example.com';  // NO trailing slash!
  • I'm using Drupal 8, in .htaccess RewriteBase is commented out, I tried uncommenting and setting to RewriteBase /, no luck. My settings.php does not have a $base_url, the closest I find is a line # $settings['file_public_base_url'] = 'http://downloads.example.com/files';, which is commented out.
    – Wade G
    Commented Oct 26, 2016 at 15:53
  • Ok, thanks for telling me about the Drupal version. Can you post the contents of your .htaccess (removing anything you don't want public). I am mostly concerned with the redirect settings. starting at:
    – Skadu
    Commented Oct 26, 2016 at 16:08
  • Starting at line 69 ending somewhere around line 121.
    – Skadu
    Commented Oct 26, 2016 at 16:09
  • Looked into this a little bit more, I'm thinking it's related to a Core D8 issues described here
    – Skadu
    Commented Oct 26, 2016 at 16:27
  • My .htaccess. In regards to the Core D8 issue you linked, I see comment #10 suggests this patch. Forgive my naivete, but how does one apply such a patch? Navigate to that file in the core, remove the - lines and add the + lines of code?
    – Wade G
    Commented Oct 26, 2016 at 16:43

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.