I've been setting up my site on a test domain. I the image links inserted in page are absolute path with the test domain like this:

Only local images are allowed.

is there way to have the src use relative path so I don't have to change when I move to the real domain?

Comments

mattyoung’s picture

I am sorry my img tag example got gobbled. Here is what it looks like:

img src="http://www.my-test-domain.com/sites/default/files/images/george-bush.JPG" alt="President George W. Bush" title="President George W. Bush" class="image image-_original " width="115" height="124"

I don't know PHP and very new to Drupal. Can you explain how to use url() or l() for this?

vm’s picture

what method are you using to insert images ?

if handcoding then you should use relative urls right out of the gate.

_____________________________________________________________________
My posts & comments are usually dripping with sarcasm.
If you ask nicely I'll give you a towel : )

-Anti-’s picture

> I the image links inserted in page are absolute path

Sorry, I'm interested in this problem - can you elaborate a bit...
What are you using to insert images inline? Is it a wysiwyg editor?
Or maybe these are attachments you're talking about?

I was under the impression that drupal would always use relative paths?

Thanks.

mattyoung’s picture

I use the img_assist module here: http://drupal.org/project/img_assist to insert the image link. It puts the src="absolute full path" in the image tag like this:

img src="http://www.my-test-domain.com/sites/default/files/images/george-bush.JPG"

I found that removing the "http://www.my-test-domain.com/" part sort of work sometimes if I visit the page directly, but if I use taxonomy to search the pages, the img tags break. So I guess I must use the url() function some how. Can someone show me how to use the function in this situation? Can I execute php code in my page content?

linuxpowers’s picture

If I'm reading your post correctly, I went through the same issues a few weeks ago myself and this is what I learned. Keep in mind, I load my images using the "img src" tag when I write the content!

Instead of dropping off the entire, "http://www.my-test-domain.com/", try leaving the "/" after the ".com".

Should now read: "/sites/default/files/images/george-bush.JPG"
instead of: "sites/default/files/images/george-bush.JPG"

At least that's what works for me! Then when you move your site over to the "REAL DOMAIN", you'll still have the correct path!

I am concerned with your path though. On my site, the "/sites" folder contains two sub-folders, "/all" AND "/default". I created all my additional folders ie: /images, /files etc in the /all folder and I noticed yours is in the /default folder! I don't see how this could be a problem if you type in the correct path. But, I do know Drupal uses the /all folder when uploading images or files and that's where it looks for them.

I'm also not to sure but I think you should, since your writing the code, use "full HTML" as your "Input Format". I don't believe it will work with "Filtered".

It's not much, but it's what I've learned so far.

Hope it helps!

mattyoung’s picture

You are right, using

src="/site/..." works all the time.

>I am concerned with your path though. On my site, the "/sites" folder contains two sub-folders, "/all" AND "/default". I created all my additional folders ie: /images, /files etc in the /all folder and I noticed yours is in the /default folder!

I didn't make that folder. I'm using 6.2 and it created the "files" folder in "sites/default/" on install. The image module then created the sites/default/files/images folder when I install it. It places upload there. And the img_assist module pickups image files there. So "site/default/files/images" folder is what image and img_assist use.

I'm going to see how to report a bug to img_assist.

-Anti-’s picture

You should probably start a bug report on the img_assist module project.
No module should be using absolute paths for internal links, IMO.