I’m working on a drupal 6 site at mydomain.com/drupalsite, and the designer has put a lot of hardcoded image paths in there, for instance a custom img folder in mydomain.com/drupalsite/img. So a lot of the site uses links to /drupalsite/img/myimg1.png.
Here’s the problem — the site is eventually moving to finaldomain.com, via pointing finaldomain.com to mydomain.com/drupalsite. So now paths like /drupalsite/img/myimg1.png will resolve to finaldomain.com/drupalsite/img/myimg1.png, instead of what should be finaldomain.com/img/myimg1.png. The finaldomain.com site has to point to that subdirectory so it hits the index.php.
My first instinct is to use an .htaccess file to replace the /drupalsite with “”, but I’ve tried about a dozen different solutions and they haven’t worked. My hack of a solution was to use some ln -s links but I really don’t like it 🙂 tia
Andrew
The best method, in hindsight, is to ensure folks use Drupal functions to make all links:
l(that’s the letter L)drupal_get_path()base_path()The
l()function takes care of base path worries, and provides a systematic way to define your URL’s. Using things liketheme_image()plus thel()function are a sure win. Use the second and third functions above if you have to write your own<a>tags and for use inside theme functions liketheme_image().But for your current situation:
As regards Andy’s solution, it would be better if you could limit your changes to certain database fields where you know the links are located.
So write a query to select all those fields (e.g. all body fields):
This, for example, will get you every
bodyfield in thenode_revisionstable, so even your old revisions would have proper links.Then run through those results, do
str_replace()on each, and then write the changes back:I’d obviously try it on one record first, to make sure your code behaves as intended (just add a
WHERE vid = 5, for example, to narrow it down to one revision). Furthermore, I haven’t taken advantage ofnode_loadandnode_save, which are better for loading and saving nodes properly, so as to provide a more general solution (for you to replace text in blocks, etc.).For your files, I’d suggest a good ol’
sedcommand, by running something like the following from within your “sites” folder:Nabbed that from here, so take a look on that site for more explanation. If you’re going to be working with paths, you’ll either need to escape the
/of the paths in your version of thesedcommand, or use a differentsedseparator (i.e. you can writes#string1#string2#instead ofs/string1/string2/, so you could writes#/drupalsite/img/#/img#instead ofs/\/drupalsite\/img\//\/img/:-). See also Drupal handbook page for quicksedcommands: http://drupal.org/node/128513.A bit of a mess, which is why I try to enforce using the proper functions up front. But this is difficult if you want themers to create Drupal content but you don’t want to give them access to the “PHP Filter” input format, or they simply don’t know PHP. Proper Drupal theming, at any point past basic HTML/CSS work, requires a knowledge of PHP and Drupal’s theme-related functions.