Hi,

I'm an HTML, PHP and Drupal newbie, so apologies if this should have been obvious.

I have a live Drupal site on nethosted.co.uk (so far so good, by the way), and a development copy on my laptop on a xampp setup.

On one of my static pages, I have some embedded hyperlinks within the html body.

Trouble is, I have to hand edit all the links to use "localhost" on my development copy, and the actual "www.xxxxxx.co.uk" on the live copy. This isn't going to work very well if I ever try to maintain the development and live copies in sync.

Is there a neat way of creating some sort of relative link that is an offset from wherever is the home page of the current website?

Thanks

David

Comments

cog.rusty’s picture

Try the pathfilter module:

http://drupal.org/project/pathfilter

Otherwise, if you are talking about image and file links, the correct way to enter them without a domain name depends on whether you are using Clean URLs or not and whether you access the site as http://example.com/subdirectory or just http://example.com

But pathfilter takes care of everything.

xqus’s picture

The trick is to make (just as you said) relative links. Take a look at this site for many examples.
http://www.mediacollege.com/internet/html/hyperlinks.html

---
Audun Larsen

cog.rusty’s picture

The problem is mostly when dealing with Clean URLs and subdirectories. Here is how:

*Without* Clean URLs:
-----------------------------
You are in http://example.com/?q=node/35
You use <img src="files/filename"> -- a relative path
It resolves to http://example.com/files/filename -- SUCCESS!

You are in http://example.com/drupal/?q=node/35 -- installed in a 'drupal' subdirectory
You use <img src="files/filename">
It resolves to http://example.com/drupal/files/filename -- SUCCESS! everything cozy here!

*With* Clean URLs:
-----------------------------
You are in http://example.com/node/35
You use <img src="files/filename"> -- just like before
It resolves to http://example.com/node/35/files/filename -- FAIL ...hmm

You use <img src="/files/filename"> -- let's try a front slash
It resolves to http://example.com/files/filename -- SUCCESS! ... we got it!

You are in http://example.com/drupal/node/35 -- installed in a 'drupal' subdirectory
You use <img src="/files/filename"> -- with a front slash again
It resolves to http://example.com/files/filename -- FAIL ...damn, the files are under drupal/files

You use <img src="/drupal/files/filename"> -- let's add the base path
It resolves to http://example.com/drupal/files/filename -- SUCCESS...

But that base path in all the links makes it hard to move a Drupal installations with Clean URLs to the web root, if it was initially installed in a subdirectory.

xgretsch’s picture

Thanks for such a comprehensive explanation, so quickly.

I'm using clean URLs and no subdirectory, so I had tried the "files/filename" method and duly failed; the "/files/filename" method works fine. I'll take my chances on needing to move to a subdirectory at a later date.

xgretsch

sdecabooter’s picture

You could also try to prefix your path with base_path() (http://api.drupal.org/api/function/base_path/5), but that'll of course only work when you use the PHP input filter, which is certainly not recommended if anyone else but you needs to add content to the site.

cog.rusty’s picture

Apparently that's what the pathfilter module does.