There appears to be a problem when moving a site from one domain to another that causes the URLs to break. Details below.

Comments

Mac Clemmens’s picture

I'm getting an error when I move my drupal installation from one domain to another. Even if I update my files path in the system, I get URLs like this:

http://subdomain.olddomain.org/sites/olddomain.org/files/sites/newdomain.org/files/resources/doc.pdf

I'm sure I'm more complicated than most, as I like to stage sites at a subdomain (and possibly at a subdomain of another domain) prior to making them live. If I manually remove sites/olddomain.org/files/ from the URL, it works. But I thought it should be resolved, as this first came up when the beta was released and still affects some sites even in RC1. All my linked files broke. Had to noodle around in SQL to fix it.

My file path is /sites/newdomain.org/files (entered at /admin/settings/file-system)

It may be worth noting that if I edit the node and click Save that the problem goes away. But if I switch back to the other domain (using the same database) and edit and save it there, it breaks on the live site. (and vice versa)

Any tips?

quicksketch’s picture

Title: invalid path / file not found » Invalid path / file not found
Category: bug » support

It's not a bug in FileField. This is the way core handles files unfortunately. You CAN'T change the file system path (ever), unless you do manual SQL updates to fix the existing files.

#324474: migrating servers issue
#427126: Moved servers, now incorrect paths

The best solution to this (as dopry mentioned in those issues), is to never use the name of the domain in your file system path. Instead make a symlink that uses a generic name.

On your dev server:

ln -s dev.example.com example

On your live server:

ln -s example.com example

Then set your file system path to sites/example/files.

quicksketch’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Mac Clemmens’s picture

Thank you - this is a great tip!

If anyone else has run into this issue like I have where you need to change the file upload path after you've already uploaded a bunch of files, you can use the following SQL commands to update the `files` table in your database:

Substitute sites/incorrectpath.org/files/ with the path you are using, and this SQL command will strip it out from the beginning of all the filepaths.

UPDATE `files` set filepath = SUBSTRING_INDEX(filepath, 'sites/[incorrectpath.org]/files/', -1);

Then you can run this SQL command to prepend the correct path at the front again, hopefully fixing the problem.

UPDATE `files` set filepath = CONCAT('sites/[correctpath.org]/files/', filepath);

Remember to BACK UP YOUR DATABASE before executing this code. It could eat your babies!

epg’s picture

Status: Closed (fixed) » Active

I have the same problem, except I'm on a windows server on my local machine. How do I fix this (a solution equivalent to the one in comment #2)?

I do not want to have to go and manually alter the database every time I upload changes from my local machine to my live server.

My live server is on bluehost. How do I implement the solution in comment#2 on bluehost?

(keep in mind I'm a complete newbie!)

Thanks!

quicksketch’s picture

Status: Active » Closed (fixed)

epg, let's keep your questions to one issue, since I'm also answering you in #409884: a way to refresh filepaths stored in database?.