Last active
November 20, 2017 04:16
-
-
Save hdodov/41e36d4aea0fc8de369786ea09a7b777 to your computer and use it in GitHub Desktop.
.htaccess file that allows you to visit a page with unminified versions of all files inside
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 | |
RewriteCond %{REQUEST_URI} \/nomin(\/|$) | |
RewriteRule (.+)\/nomin(.*) $1$2 [E=NO_MINIFICATION:1] | |
RewriteCond %{ENV:NO_MINIFICATION} 1 [OR] | |
RewriteCond %{ENV:REDIRECT_NO_MINIFICATION} 1 | |
RewriteCond %{REQUEST_URI} (.+)\.min(\.[^.].*) [NC] | |
RewriteCond %{DOCUMENT_ROOT}/%1%2 -f | |
RewriteRule .+ %1%2 [NC,L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does it do?
When working on a project, you often have minified versions of your files for production and unminified for development. You need to switch between the two quite often and it can be very annoying if you have to do it by hand.
With this gist in your .htaccess, you can simply navigate to your project folder with
nomin/
prepended and all minified files will have their unminified version served (if it exists). This means if you can work with your human-readable files without having to change a single URL in your source code. When you're done with your changes and they are minified, simply removenomin/
and see how the minified versions work. If everything is alright - push to production and that's it! No URLs changed in the whole process.Example usage
First, you have to include the gist in an .htaccess file (obviously), preferably in the root. Then, you simply navigate to a folder.
For example, this:
will serve files from:
But all files that have
.min
in their filename will be substituted for their non-minified versions (without.min
). If a minified file doesn't have an unminified version, it will be served as is.You can put
nomin/
anywhere in the URL. However, it won't work if you put it:nomin
folderhttp://localhost/nomin/mysite/myproject/