MattWilcox / Adaptive-Images

Automatically adapts your existing HTML images for mobile devices. No mark-up changes needed.
http://adaptive-images.com/
1.76k stars 229 forks source link

WordPress multisite integration #189

Open ingozoell opened 8 years ago

ingozoell commented 8 years ago

I tried to include the functionality of adaptive images into a WP multisite but only the primary site works fine. Every other site creates a subfolder into the upload folder where all files are stored like:

Primary Site: uploads/
Other Site: uploads/sites/2
Other Site: uploads/sites/3

It became just broken images on my sub-sites, but the urls of all images are right. I installed WP multisite in subfolder like this: http://domain.de/site2

--- UPDATE ---

My .htaccess file

# --------------------------------------------------------------------------------------------------------------
# Adaptive-Images
# http://adaptive-images.com
# --------------------------------------------------------------------------------------------------------------

<IfModule mod_rewrite.c>
RewriteEngine On

    RewriteCond %{REQUEST_URI} !wp-admin
    RewriteCond %{REQUEST_URI} !wp-includes
    RewriteCond %{REQUEST_URI} !wp-content/plugins
    RewriteCond %{REQUEST_URI} !wp-content/cache
    RewriteCond %{REQUEST_URI} !wp-content/ai-cache

    RewriteCond %{REQUEST_URI} wp-content/uploads
    RewriteCond %{REQUEST_URI} wp-content/uploads/sites/2
    RewriteCond %{REQUEST_URI} wp-content/uploads/sites/3

    RewriteRule \.(?:jpe?g|gif|png)$ path/to/adaptive-images.php [L]

</IfModule>

# BEGIN WordPress
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?((wp-content|wp-admin|wp-includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress

My adaptive-images.php (except)

/* CONFIG ----------------------------------------------------------------------------------------------------------- */

$resolutions   = array(1600,1280,960,768,600,480); // the resolution break-points to use (screen widths, in pixels)
$cache_path    = "path/from/document_root/to/ai-cache"; // where to store the generated re-sized images. Specify from your document root!
$jpg_quality   = 90; // the quality of any generated JPGs on a scale of 0 to 100
$sharpen       = TRUE; // Shrinking images can blur details, perform a sharpen on re-scaled images?
$watch_cache   = TRUE; // check that the adapted image isn't stale (ensures updated source images are re-cached)
$browser_cache = 60*60*24*7; // How long the BROWSER cache should last (seconds, minutes, hours, days. 7days by default)

/* END CONFIG ----------------------------------------------------------------------------------------------------------
------------------------ Don't edit anything after this line unless you know what you're doing -------------------------
--------------------------------------------------------------------------------------------------------------------- */

/* get all of the required data from the HTTP request */
$document_root  = $_SERVER['DOCUMENT_ROOT'];
$requested_uri  = parse_url(urldecode($_SERVER['REQUEST_URI']), PHP_URL_PATH);
$requested_file = basename($requested_uri);
$source_file    = $document_root.$requested_uri;
$resolution     = FALSE;

Thanks for your help
Ingo