WordPress.org

Ready to get started?Download WordPress

Forums

Noob, relative paths, images, and subdomains (9 posts)

  1. MikeLesser
    Member
    Posted 8 years ago #

    Newbie seeks advice. I only have a minimum of WP jargon so far, which may be the problem.

    My first test blog has a couple of postings. The blog is located at
    <http://macflair.com/blog/>

    The postings have some embedded images, using relative paths, a la:
    <img src="/blog/wp-content/uploads/2006/05/MyPix.png" etc >

    This worked just fine. Now comes the trouble. I created a subdomain on this server with good ol' cpanel: <blog.macflair.com>. This resolves to <http://macflair.com/blog/>

    Now the 'front' page created by WP has an extra, unecessary 'blog/' in the path. The individual posting pages are fine. I can remove the 'blog/' part of the tags and reverse the results. My question is then, do people use absolute paths (that seems odd), or is there another level of manipulation that must be performed in order to use a subdomain? I also realize that going into the individual postings results in the default URL of (for example) <http://macflair.com/blog/?p=9>, which I need to deal with anyway.
    TIA!

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    If you want it to work with both URL structures, then yes, you'll have to use absolute links. This is not specifically a wordpress problem, it has to do with the way the URL is resolved.

    You're specifying the relative links as /blog/blah/blah.. When the browser gets this, it resolves it to http://yourserver.com/blog/blah/blah...

    But when you changed the domain to blog.yourserver.com, and have apache shift that by adding the /blog folder to it internally, then yes, now your links are wrong.

    Can't have it both ways.

    Well, you *could* have it both ways with some rewriting. Basically you'd check to see if the url contains "blog.yourserver.com" and eliminate the offending "/blog" from the URL if so. You could do this in .htaccess or httpd.conf.

  3. MikeLesser
    Member
    Posted 8 years ago #

    Thanks for responding. So, am I correct in assuming that absolute links is the way to go, that is, it's what people normally do? It makes sense of course, but I wonder what happens when people try to move their entire blog? Is my method of inserting <img> tags right into the posting considered odd?

    I think I get the reference to the bit about removing the offending part of the path. This is similar to the snippets I've seen about protecting images and such. I add the bits into .htaccess to manipulate the URL as I see fit, including eliminating requests for images that don't come from my own domain. Is that about right?

    I just (in the last few mins) added the bits to use the name & slug in my URLs, which is a step in that direction. I can't recall any examples at the moment, but my intent is to have my URLs (in addition to being maintainable) look something like:

    <blog1.mydomain.com/datestuff/slug>
    <blog2.mydomain.com/datestuff/slug>

    Would this be considered a horrifying faux pas or something? I freely admit to being a noob and ignorant of most netiquette. Thx, Mike

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    The more usual approach is to use only one url or the other. Trying to use both example.com/blog and blog.example.com is the problem here.

    If you are trying to permanently move your blog to the new domain name, and don't care about the old URL working anymore, then the easiest way to deal with it is simply to edit all your old posts to remove the /blog thing. This is easier than it sounds if you have control of the database. Use the database backup plugin to generate SQL dumps of the database, open them in a text editor, search+replace, run the SQL to rebuild the database.

    Alternatively, use URL rewriting to remove the "/blog" on the new domain. This handles your old posts okay, and then for new posts you can simply not put it there.

    Very generally speaking, people don't move blogs around. It's one thing to change hosting, it's another to change the existing URL structure of an already established blog. Changing hosts is easy. Changing URL structure is fraught with perils, as you now see. :)

    Also, if you have very few posts on this blog, then you can probably just go edit the old posts quicker than screwing around with rewrites and such. But then if you have 10k posts, that's probably not a good option. ;)

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 8 years ago #

    Oh, and very generally speaking, you want to use absolute URLs for everything. Why? RSS feeds. RSS Readers may not be able to display your images correctly if you use relative links.

    But that's a matter of debate, really.

  6. moshu
    Member
    Posted 8 years ago #

    I don't know about your cPanel, Mike, but in mine when setting up a subdomain I can choose whether to redirect to a folder or not.
    When it is a redirect - nothing will work properly, I call them the fake subdomains.
    If not redirected, then WP understands the
    subdomain.domain.com URIs in the Options.
    (This is based on own personal experience AND the countless posts here complaining about the same as you did)

  7. MikeLesser
    Member
    Posted 8 years ago #

    Okay let me absorb...

    Absolute URLs to images - check
    Don't sweat absolute URLs or fixing existing posts - check
    I want to use my subdomain, and not redirect - I think?
    And the Options will allow WP to use the subdomain (sans redirection) automatically- I think?

    I need to try this tonite and see.
    Thanks guys

  8. MikeLesser
    Member
    Posted 8 years ago #

    Hmm. I've canceled redirection. Assuming I'm not suffering from a subdomain issue...

    I've set my Options up like so:
    WP address: domain.com/blog
    Blog address: blog.domain.com
    for my blog which currently resides at the address domain.com/blog.

    Entering the URL blog.domain.com sucessfully loads the 'main' page, the same as it did when I had redirection to domain.com/blog. That was easy.

    However, the clicking on the posts will now attempt to load a page at
    blog.domain.com/<datestuff>/<slug> (I have edited the blog root's .htaccess for this form)

    This always fails with a 500 error. I've just realized that my blog is not at the root level, but in a folder within root; the account is set up by the provider as
    /public-html/blog/
    Since I've never used the /public-html/ path segment anywhere in setting up anything, does that mean the provider has some kind of redirection set up on his end (httpd, et al)?? I'm starting to get confused...

  9. moshu
    Member
    Posted 8 years ago #

    WP address: domain.com/blog
    Blog address: blog.domain.com

    What I was trying to say: if you have a "normal" subdomain (not redirected anywhere!!!) then the two URIs should be the same.
    Whether the subdomain is real or not should be set on your site's level, not in the WP's admin.

Topic Closed

This topic has been closed to new replies.

About this Topic