Ron van der Heijden
Ron van der Heijden

Reputation: 15080

How to use dynamic path for images in Wordpress 3.6.1

Currently I am working on a Wordpress website.

I have multiple websites on my webserver so my Wordpress site is located at http://localhost/wordpress/

Now I want to have dynamic paths for my images.

As HTML for my logo I use

<img src="images/logo.png" />

And in my .htaccess I use

RewriteRule ^images/(.*)$ wp-content/uploads/$1 [L]

This is only working on my homepage. When I go to the contact page http://localhost/wordpress/contact

I need to change my logo HTML to <img src="../images/logo.png" /> to have it working on the pages.

How can I point my htaccess record to the root so that I allways can use the path images/(.*)?

I think I forget the RewriteCond but I have tried some and nothing works, even some internal server errors appears.

How can I do this?

My complete .htaccess looks like

# BEGIN WordPress
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ - [L]

    RewriteRule ^images/(.*)$ wp-content/uploads/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress

Upvotes: 1

Views: 915

Answers (1)

anubhava
anubhava

Reputation: 785491

Make sure to use absolute URLs for images which would always start with /

 <img src="/images/logo.png" />

And in your DOCUMENT_ROOT/.htaccess use same rule i.e.

RewriteRule ^images/(.+)$ /wordpress/wp-content/uploads/$1 [L,NC]

Upvotes: 2

Related Questions