WordPress.org

Ready to get started?Download WordPress

Forums

Can XML-RPC upload return a relative URL? (9 posts)

  1. willismorse
    Member
    Posted 9 years ago #

    When my blog program uploads images to my WP 1.2 site, it gets back an absolute URL to the image. Because my blog lives at a forwarded domain, this means the image URLs and the blog URL look like they resolve to different domains, which triggers all sorts of browser and firewall image filters. The end result is that many people can't see the images in my blog.

    Is it possible to set WP 1.2 (or 1.5, for that matter) to return a relative URL from the upload function instead of an absolute URL?

    Thanks,
    Willis Morse

  2. Lorelle
    Member
    Posted 9 years ago #

    This is a pretty sophisticated question. Have you looked into the .htaccess rewrite/redirects? That is probably where your answer lies, which is outside of the basic WordPress scope.

  3. OtherMichael
    Member
    Posted 9 years ago #

    Well, I agree. Why does WP have to have absolute URLs on uploads?

    When I backup up the db to my localhost, all the image-links break. As when I've migrated to different Domain-names.

    I can MySQL-change them all, but I wish I didn't have to.

  4. moshu
    Member
    Posted 9 years ago #

    OtherMichael,
    there might be other reasons, too, but I can tell you one (for having absolute URLs for uploaded images). Assume, your images are in the wp-content folder, which resides directly under the WP root. You put an image in a post with a relative path like wp-content/myimage.jpg and when I'm looking at your index.php - everything is fine, because the path from there will be: mysite/blog/wp-content/myimage.jpg.
    But when I click on the permalink (title) to go to single post view, everything will change to:
    mysite/blog/2005/05/06/posttitle/wp-content/myimage.jpg
    As a result no picture, just an error on the page.

  5. willismorse
    Member
    Posted 9 years ago #

    The problem with the domains is that the domain forwarding is being done by NetworkSolutions. I'm not using rewrite rules in Apache to do this. My Apache server never sees anything about the virtual domain, it just gets an URL into the actual domain. This forwarding is a service that NetworkSolutions just starting offering, so it may become an issue for more users.

    I tried an experiment and hand modified the image links in one entry to be relative URLs. Everyone that couldn't see them before can see them now. So the domain conflict oes seem to be the problem.

    When I click on the entry title (permanant link), the relative image URLs still resolve properly, because it's still just index.php. Is this behavior going to be different in 1.5? I'm still using 1.2.

    Thanks for the replies,
    Willis Morse

  6. willismorse
    Member
    Posted 9 years ago #

    I can MySQL-change them all, but I wish I didn't have to.

    That brings up my next question. I've now got go back relative-ize a whole ton of image links in many many entries. Any thoughts on an easy SQL (or other) way to do this kind of bulk edit?

    Willis Morse

  7. moshu
    Member
    Posted 9 years ago #

    I have to correct myself, at least partially.
    The problem I've described above I encountered when having a "fixed" image in the sidar (WP.1.2.x). Sorry, it was a long time ago, so I had to re-check it. As you said, Willis, in the posts the relative image path work well in 1.2
    However in 1.5 where most of the themes have a single.php template for displaying the single post view (when clicking on the permalink) the relative path does NOT work. See the post "image alt test" on my testbed.

  8. willismorse
    Member
    Posted 9 years ago #

    However in 1.5 where most of the themes have a single.php template for displaying the single post view (when clicking on the permalink) the relative path does NOT work.

    Bummer, you're right.

    I'm also wondering how one goes about moving a WP site to a different location. There should be a more template-based solution for this problem, because the absolute urls are also going to break if you move WP on your server, or move it to a different domain.

    The real solution for this is to have a template variable that knows where the image folder is, and can generate an absolute URL as needed at render time. I don't know enough about the WP 1.5 architecture to know whether this is doable. I suppose all those image plugins deal with this problem.

    Willis Morse

  9. OtherMichael
    Member
    Posted 9 years ago #

    Perhaps I using the wrong terms.

    An absolute URI like "/wp-content/images/2005/pwned.jpg" will always be accurate in relationship to the root, but when the "http://[site URL]" is appeneded, thigns are no longer happy when "mirroring" to localhost or changing domain names.

    to do a MySQL replacement in your fields try something like this:

    'update TABLE set FIELD = REPLACE(FIELD, 'http://www.RemoteHost.com', '<replace with this string>') '

    If your replacement is '' (nothing) all should be well.

    SHOULD be well. Try this technique on a local-copy of your DB first, to make sure you've got the syntax correct.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.