By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,510 Members | 1,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,510 IT Pros & Developers. It's quick & easy.

Make a relative url path from an absolute path to another one

P: n/a
Hi,

I'm sometimes brain dead for a simple problem like this one :

Given an origin absolute URL and a destination absolute URL, I want to make
a relative path from the origin to the destination.

e.g

origin = http://www.stuff.com/x/y/foo.html
destination = http://www.stuff.com/x/bar.html

-> ../bar.html

origin = http://www.stuff.com/x/bar.html
destination = http://www.stuff.com/x/y/foo.html

-> y/foo.html

Many thanks for any hint.

--
Gilles

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Am Mon, 27 Oct 2003 15:18:38 +0100 schrieb Gilles Lenfant:
Hi,

I'm sometimes brain dead for a simple problem like this one :

Given an origin absolute URL and a destination absolute URL, I want to make
a relative path from the origin to the destination.


I did this some time ago:
http://guettli.sourceforge.net/gthum...elative_url.py

Hope that helps,
Thomas

Jul 18 '05 #2

P: n/a
"Thomas Guettler" <gu*****@thomas-guettler.de> a écrit dans le message de
news: pa****************************@thomas-guettler.de...
Am Mon, 27 Oct 2003 15:18:38 +0100 schrieb Gilles Lenfant:
Hi,

I'm sometimes brain dead for a simple problem like this one :

Given an origin absolute URL and a destination absolute URL, I want to make a relative path from the origin to the destination.


I did this some time ago:
http://guettli.sourceforge.net/gthum...elative_url.py

Hope that helps,
Thomas


It helped of course (it's exactly what I needed)

Many thanks Thomas

--
Gilles

Jul 18 '05 #3

P: n/a
Gilles Lenfant wrote on Mon, 27 Oct 2003 15:18:38 +0100:
I'm sometimes brain dead for a simple problem like this one :

Given an origin absolute URL and a destination absolute URL, I want to make
a relative path from the origin to the destination.

e.g

origin = http://www.stuff.com/x/y/foo.html
destination = http://www.stuff.com/x/bar.html


You could split the strings at every "/" and compare the items of the two
resulting lists until two unidentical items are found. Then you've found
the common bit and the different bit and it's not that hard to make a
relative link for that.

--
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
ce******@bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
ernq gur yvfg, fb gurer'f ab arrq gb PP.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.