I'm using ExpressionEngine to build a site, and have a development version running locally via WAMP. Within the root "www" folder, I have an "ee" subdirectory that acts as the root of the development site. There is an "images" folder directly within "ee" that contains all images for the site. On the live server, the image paths require "/images/...", however on my dev server, if I use the same path it will map to "localhost/images/..." not "localhost/ee/images..." and therefore result in broken links.

I'm wondering if there's an adjustment I can make to the .htaccess file to get the links mapping properly on my local server? At this point, in order to get images to show, I need to use "images/..." which will not work on the live server.

Thanks for any assistance here.

  • I cannot think of a way unless your images had something like eeimage.jpg instead of image.jpg to identify them. You can then use .htaccess and a regular expression to make it work. When you need to copy the files into production, you can just rename them. This would be a pain if you have a lot of them of course. This is not a pretty solution, but that could work. I hope someone has a better answer!
    – closetnoc
    Nov 14 '14 at 2:33
  • Thanks for the response- for some reason the live server doesn't like "images/..." And the local server doesn't like "/images/..." so I'd like to make some kind of (htaccess) adjustment to sync the two environments and make the transition seamless...
    – nickpish
    Nov 14 '14 at 3:13
  • Sounds like one of those catch 22 deals. I will have to think on this. Perhaps a symlink for each image from production to dev? More work, but may be a solution. I often forget about symlinks.
    – closetnoc
    Nov 14 '14 at 5:14

You should really solve this by setting the DocumentRoot correctly on your local test server. Perhaps setup a VirtualHost for this test site, rather than changing your default server config if you are testing several sites? It is a local test server, so should reflect the settings of the live site as close as possible.

However, it is possible (but not recommended) to "fix" this with mod_rewrite in .htaccess. (Although if you have your own server then it will be more efficient in your server config, not .htaccess.) So, purely as an academic exercise, you could do something like:

RewriteEngine On
RewriteRule ^images/(.*) /ee/images/$1 [L]

This internally rewrites all requests for /images/ to /ee/images/. (This will obviously break your live site if accidentally uploaded.)

But, you are likely to have more problems with client-side paths... what about all your CSS and JavaScript files etc?

  • thanks for your response; how would I go about setting the DocumentRoot on my local test server? Is this via an Apache config file? As far as CSS, JS, etc. the thing that's baffling to me is that images referenced in CSS with "images/..." work properly-- it's only in the markup that image links referenced in this way don't seem to work; I don't know if this is something unique to the configuration of ExpressionEngine, but it makes little sense. Linking to actual CSS and JS files is not an issue. I will give your htaccess rule a shot and report back. Thanks again.
    – nickpish
    Nov 16 '14 at 5:36
  • There is a DocumentRoot directive in httpd.conf (your main Apache config file). You will need to change the appropriate <Directory> block also to reflect this path. You also need to restart Apache after each change to the server config. Relative paths in a CSS file are relative to the CSS file, not the HTML document.
    – MrWhite
    Nov 16 '14 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.