Hi,
I have 2 problems with rewrites for MODX Cloud:
1. Rewrite static.mydomain.com to assets folder
I want this subdomain to point to the /assets/ folder of my Cloud. I tried to set the root for this subdomain like this:
location / {
if ($host = 'static.chsmedien.com') {
root /paas/cxxxx/www/assets/;
}
try_files $uri $uri/ @modx-rewrite;
}
...but this is not working.
2. Send retina images based on cookie
Based on this
http://shauninman.com/tmp/retina/, I'm setting a cookie in the browser and the webserver should send @2x images. But this doesn't work, too.
location ~* \.(?:ico|gif|jpe?g|png)$ {
expires 355d;
# Serves static files in high resolution only if required
# Naming convention for high resolution images:
# [filename]@2x[extension], e.g.:
# [email protected]
set $hidpi_uri $1@2x$2;
if ($http_cookie !~ 'device-pixel-ratio=2') {
# If the device-pixel-ratio cookie is not set to 2, fall back to
# default behaviour, i.e. don't try to serve high resolution image
break;
}
# device-pixel-ratio cookie is set to 2
# Serve high resolution image if available,
# otherwise fall back to standard resolution
try_files $hidpi_uri $uri =404;
}
My complete rules:
# x-ua-xompatible header
add_header X-UA-Compatible IE=edge,chrome=1;
# expire headers for assets
# 1: images
location ~* \.(?:ico|gif|jpe?g|png)$ {
expires 355d;
# Serves static files in high resolution only if required
# Naming convention for high resolution images:
# [filename]@2x[extension], e.g.:
# [email protected]
set $hidpi_uri $1@2x$2;
if ($http_cookie !~ 'device-pixel-ratio=2') {
# If the device-pixel-ratio cookie is not set to 2, fall back to
# default behaviour, i.e. don't try to serve high resolution image
break;
}
# device-pixel-ratio cookie is set to 2
# Serve high resolution image if available,
# otherwise fall back to standard resolution
try_files $hidpi_uri $uri =404;
}
# 2: js/css
location ~* \.(?:js|css)$ {
expires 30d;
}
# Built-in filename-based cache busting
# This will route all requests for /css/style.20120716.css to /css/style.css
# Read also this: https://github.com/h5bp/html5-boilerplate/blob/master/doc/htaccess.md#cache-busting
location ~* (.+)\.(\d+)\.(js|css)$ {
try_files $uri $1.$3;
}
# modx furls rewrite
location / {
if ($host = 'static.chsmedien.com') {
root /paas/c0073/www/assets/;
break;
}
try_files $uri $uri/ @modx-rewrite;
}