WordPress – prevent image files rewriting when using postname

I have WordPress set to rewrite by postname in the admin permalink settings.

I use root paths for images in a gallery, eg,

Read More
/wp-content/themes/bones/images/portfolio/house.jpg

But the images are being rewritten to start with the post name, eg,

http://mysite.dev/design/wp-content/themes/bones/images/portfolio/house.jpg

… and so getting 404 responses.

How do I alter my access file to stop this happening? Here is the access file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

I don’t want to use the full URL for the images, that’s why I want a htaccess file solution.

Related posts

Leave a Reply

1 comment

  1. Permalink settings only apply to your pages/blog etc. – not for links that you use in your posts or template.

    If you use /images/portfolio/house.jpg in your post, they are certainly going to added to the current URL of where you are atm, e.g if you are on http://mysite.dev/design/, it’s gonna be http://mysite.dev/design/wp-content/themes/bones/images/portfolio/house.jpg.

    Hence in your post you could try:

    <img src="../wp-content/themes/bones/images/portfolio/house.jpg"> 
    

    (which is not very pretty) or use the full URL (which is wordpress default)

    In your template use:

    <?php echo get_bloginfo('template_url'); ?>/images/portfolio/house.jpg