Created
January 15, 2016 03:25
-
-
Save lackneets/f72da6e03c93f0e89a4e to your computer and use it in GitHub Desktop.
Redirect to minified version images
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> | |
RewriteEngine On | |
RewriteBase / | |
# %{ENV:BASE} is current url path | |
# See http://stackoverflow.com/questions/21062290/set-rewritebase-to-the-current-folder-path-dynamically | |
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$ | |
RewriteRule ^(.*)$ - [E=BASE:%1] | |
# foo/xxx.png => foo/min/xxx-min.png if exists | |
RewriteCond %{DOCUMENT_ROOT}%{ENV:BASE}$1min/$2-min.$3 -f | |
RewriteRule ^(.*\/)(.*)\.(png|jpg)$ %{ENV:BASE}$1min/$2-min.$3 | |
# foo/xxx.png => foo/xxx-min.png if exists | |
# RewriteCond %{DOCUMENT_ROOT}%{ENV:BASE}$1$2-min.$3 -f | |
# RewriteRule ^(.*\/)(.*)\.(png|jpg)$ %{ENV:BASE}$1$2-min.$3 | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment