• I just coverted my blog over to using Permalinks instead of the typical mess of question marks and ampersands. It really was easy but I wanted to drop a note out here for people considering doing this.

    When I add images to WordPress instead of putting in the full URL of the images (https://mydomain.com/pics/image.jpg) I always used relative URLS (pics/image.jpg).

    The reason I did this was because I wasn’t (and still am not) sure I want to stick at the domain name I have perminetly. Changing the address would mean my images still displayed fine.

    With permalinks though, my images do not display under all circumstances. A visit to https://www.dubyadubyadubyadotcom.com/ will show a couple of images however if I enter the post https://www.dubyadubyadubyadotcom.com/2005/01/30/dear-elle-macpherson/ the images no longer appear. This is because the browser is looking for the images to appear at https://www.dubyadubyadubyadotcom.com/2005/01/30/dear-elle-macpherson/pics/ which is not where they are.

    I now have to run queries to alter all the image tags in my database to account for this – nothing particularly taxing however iit is something worth noting as a side affect of using permalinks.

Viewing 11 replies - 1 through 11 (of 11 total)
  • I experienced this as well. Luckily, the site I’m working on only recieved its first post today, so changing the img tag was simple.

    Is this the expected behavior, or is something actually wrong here?

    Edit: Changing the img tag to use a full URL had no effect. Anyone have a solution?

    Moderator James Huff

    (@macmanx)

    URL please…

    For what it’s worth, you don’t have to put the whole URL into your image tags. You can for example use /pics/image.jpg (note the leading slash) which will work fine.

    It’s because permalinks (or mod_rewrite) fake the browser into seeing a different directory structure. For all intents and purposes, as long as you have permalinks enabled, your post is in the directory called “post-name”, in the directory called “08”, which is in the directory “2002”, which is in the public_html directory.

    Sooo….if you use relative urls, it will naturally think your image is in /2002/08/post-name/pics.

    Just do as dbowen suggested, and use an absolute URL. It doesn’t have to be the whole thing including domain name. “/” is the equivalent as “www.yourdomain.com/”. Just the same, “/pics” would be like saying “www.yourdomain.com/pics”.

    If you change your images to reference like this, then it shouldn’t be a problem when you want to switch domain names. ??

    Just as a matter of interest then, what does “./” mean [note the dot].

    I have seen it a few times but do not really understand it.

    Current directory. And “../” means one level up.

    I’m using an absolute URL/path and I’m still seeing a problem. You can see it in action with a description here:

    https://www.rreynolds.net/test-post/

    My site structure is a bit different, so I am not sure this will help.
    My blog is in a folder called “wp” and the images in wp/wp-content/.
    Now if I start my image path like this:
    /wp/wp-content/image.jpg
    it works perfectly.
    When I delete the /wp part, i.e. using only this
    /wp-content/image.jpg – I get the same resuilt as on your page: only the “alt” text is displayed.

    Something else that I’ve noticed recently is that with permalinks enabled, the link now results in a 404 even though the URL is valid. Again, when I disable permalinks or rename my .htaccess file the image returns and the link works.

    Update: I’ve had to disable permalinks for now. I have some other content on the same domain that was being effected. I’ll have to revisit this at a later time.

    I’m having this problem also: I can see the pix in the main page, but on the single post/comment page, they can’t be seen. I’m using “./blahblah” but I also tried just “blahblah.” I’m not eager to use full paths since the site will eventually change servers and directory layout.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Relative Paths to Images and Permalinks’ is closed to new replies.