[wp-hackers] Why always absolute paths?

John Bloch jbloch at olympianetworks.com
Wed Apr 21 13:16:20 UTC 2010


No. He's right. A relative path that begins with a slash assumes that the path is prefaced only by the domain. If I have http://www.example.com/ and use a src of "/images/img.jpg", it looks like http://www.example.com/images/img.jpg. If I have WP installed at http://www.example.com/blog and use an src of "/images/img.jpg" the browser still interprets it as http://www.example.com/images/img.jpg, not the correct way: http://www.example.com/blog/images/img.jpg.

Relative src's fix THAT problem (i.e. an src of 'images/img.jpg' would get the correct http://www.example.com/blog/images/img.jpg path). However, that creates a new problem: if WP is using SEF permalinks (i.e., anything but http://www.example.com/?page_id=2), you'll have a page that looks like this: http://www.example.com/blog/about-us. Using the slash at the beginning of the src creates this path: http://www.example.com/images/img.jpg (wrong). Using no slash at the beginning makes the path look like this: http://www.example.com/blog/about-us/images/img.jpg (also wrong).

Basically, you can't have relative paths if you also want to have SEF urls.

On Apr 21, 2010, at 8:58 AM, Stephen Rider wrote:

> 
> On Apr 21, 2010, at 6:46 AM, Bumbu Alex wrote:
> 
>> if you use sef url and you'll give relative path for the image (ex.
>> images/top.jpg)
>> 
>> so on page _http://page.com/ you'll have src to _
>> http://page.com/images/top.jpg
> 
> Correct.
> 
>> you can use such src as /images/top.jpg and for the above examples you'll
>> have tha same link _http://page.com/images/top.jpg
>> but when somebody will have WP installed in subdirectory, but he will use
>> default template, instead of getting
>> _http://page.com/blog/images/top.jpg
>> he will have
>> _http://page.com/images/top.jpg
> 
> ???  If WP is installed in a subdirectory, the root path would include the subdirectory.  I still don't see the problem with root paths.
> 
> I've wondered this myself regarding links to media put on a site with the uploader.  Why full URL with the path?  If I move domains or something I have to go into the database and change the URLs for all those links.
> 
> Stephen
> 
> 
> 
> 
>> =========
>> 
>> so only using absolute path is friendly for all cases
>> 
>> p.s. when I am doing my templates(for any CMS) I try to include all possible
>> images through css, so usually I have no images, or few of them (I am
>> speaking about images from template but not from posts)
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
> 
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list