Masking wp-content/themes/name/images to just images directory using htaccess

Check out the Roots WordPress Theme. They seem to do exactly what you want with the URLs.

Here’s a snippet from their roots-htaccess.php file:

add_action( 'generate_rewrite_rules', 'roots_add_rewrites' );

function roots_add_rewrites($content) {
  $theme_name = next( explode( '/themes/', get_stylesheet_directory() ) );
  global $wp_rewrite;
  $roots_new_non_wp_rules = array(
    'css/(.*)' => 'wp-content/themes/' . $theme_name . '/css/$1',
    'js/(.*)'  => 'wp-content/themes/' . $theme_name . '/js/$1',
    'img/(.*)' => 'wp-content/themes/' . $theme_name . '/img/$1',
  );
  $wp_rewrite->non_wp_rules += $roots_new_non_wp_rules;
}

Note: if you can pull this off directly in a .htaccess file, as in ZweiBlumen’s answer, you should pick that solution since it most probably is more optimized.

Leave a Comment