Created
February 11, 2022 12:49
-
-
Save anveno/ad00920fd462dcd4a5d90bf525581596 to your computer and use it in GitHub Desktop.
Redaxo: WebP images with htaccess
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<IfModule mod_rewrite.c> | |
# ENABLE REWRITING | |
RewriteEngine On | |
# Workaround for RewriteBase | |
# Copied from https://github.com/symfony/symfony-standard/blob/master/web/.htaccess | |
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | |
RewriteRule ^(.*) - [E=BASE:%1] | |
RewriteRule ^sitemap\.xml$ %{ENV:BASE}/index.php?rex_yrewrite_func=sitemap [NC,L] | |
RewriteRule ^robots\.txt$ %{ENV:BASE}/index.php?rex_yrewrite_func=robots [NC,L] | |
# REWRITE RULE FOR SEO FRIENDLY IMAGE MANAGER URLS | |
## fr: webp safari START | |
# 1. alle Browser die Webp unterstützen (und das auch via HTTP_ACCEPT mitteilen) | |
RewriteCond %{HTTP_ACCEPT} image/webp | |
RewriteRule ^media/([^/]+)/(.*) %{ENV:BASE}/index.php?rex_media_type=$1&rex_media_file=$2&%{QUERY_STRING} [B] | |
# 2. Safaris die Webp unterstützen: | |
RewriteCond %{HTTP_USER_AGENT} Mozilla.*Version/(\d{2}).*Safari | |
RewriteCond %1 >13 | |
RewriteRule ^media/([^/]+)/(.*) %{ENV:BASE}/index.php?rex_media_type=$1&rex_media_file=$2&%{QUERY_STRING} [B] | |
# 3. Safaris die Webp nicht unterstützen | |
###RewriteCond %{HTTP_ACCEPT} !image/webp # funzt nicht | |
RewriteCond %{HTTP_USER_AGENT} Mozilla.*Version/(\d{2}).*Safari | |
RewriteCond %1 <14 | |
RewriteRule ^media/(?!.*__.*)([^/]+)/(.*) %{ENV:BASE}/index.php?rex_media_type=$1_safari&rex_media_file=$2&%{QUERY_STRING} [B] | |
RewriteRule ^media/([^/]+)(__)([^/]+)/(.*) %{ENV:BASE}/index.php?rex_media_type=$1_safari__$3&rex_media_file=$4&%{QUERY_STRING} [B,L] | |
## fr: webp safari END | |
RewriteRule ^mediatypes/([^/]*)/([^/]*) %{ENV:BASE}/index.php?rex_media_type=$1&rex_media_file=$2 | |
#RewriteRule ^media/([^/]+)/(.*) %{ENV:BASE}/index.php?rex_media_type=$1&rex_media_file=$2&%{QUERY_STRING} [B] | |
RewriteRule ^media/(.*) %{ENV:BASE}/index.php?rex_media_type=default&rex_media_file=$1&%{QUERY_STRING} [B] | |
# deprecated | |
RewriteRule ^images/([^/]*)/([^/]*) %{ENV:BASE}/index.php?rex_media_type=$1&rex_media_file=$2&%{QUERY_STRING} [B] | |
RewriteRule ^imagetypes/([^/]*)/([^/]*) %{ENV:BASE}/index.php?rex_media_type=$1&rex_media_file=$2 | |
# existing files will not be overwritten | |
RewriteCond %{REQUEST_FILENAME} !-f | |
# existing folders will not be overwritten | |
RewriteCond %{REQUEST_FILENAME} !-d | |
# treats symbolic links as pathname | |
RewriteCond %{REQUEST_FILENAME} !-l | |
RewriteCond %{REQUEST_URI} !^/?redaxo/.*$ | |
RewriteRule ^(.*)$ %{ENV:BASE}/index.php?%{QUERY_STRING} [L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment