1

I am building a drupal 7 site on my localhost with ckeditor (7.x-1.13), HTML Purifier (7.x-1.0).

I realized that when my ip changes on the network, the links to the images I upload from ckeditor are broken. As I checked the html source, I saw that they are absolute urls and are using the previous ip as a part of them. Now that the ip is different, they are broken.

I need to develop the site and enter most of the content on localhost and if I cannot solve this problem, things will get complicated when I move the site to the server.

After reading a related question (D7 - Losing images when moving site location; placeholders point to old absolute path rather than relative path) I tried installing pathologic (7.x-2.11) module, checking the settings for text formats, clearing the cache with no result.

Is there a way to make ckeditor to use relative paths for images? Would it have any disadvantages?

2

You should always use relative paths in your content to avoid the problem you now have.

If it was me I would fix the links in the database so they are all relative. You can do so with sql queries like this:

UPDATE field_body_data
SET body_value = REPLACE(body_value, 'http://example.com/', '/')
WHERE body_value LIKE '%http://example.com/%';

Followed by:

UPDATE field_body_data
SET body_value = REPLACE(body_value, 'http://example.com', '/')
WHERE body_value LIKE '%http://example.com%';

There are two to catch the case you might have a path to the home page without a trailing slash.

You would have to do this for any text area field that might contain a hyperlink.

The Pathologic module will also help you around this issue. You add the pathologic input filter for your relevant formats, then configure it with your old domain name. Also add the domain name / This will make it change relative paths to use their alias, like /node/10 to be /node-path-alias

That last feature with the aliases is very useful.

See https://drupal.org/node/257026 for more info on configuring pathologic.

  • To be clear, if you use Pathologic as suggested in the latter half of this answer, it can be configured so that doing the replacement with SQL queries, as in the first half, is not necessary. – Garrett Albright Sep 9 '14 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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