Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hdodov
Last active November 20, 2017 04:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdodov/41e36d4aea0fc8de369786ea09a7b777 to your computer and use it in GitHub Desktop.
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
<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>
@hdodov
Copy link
Author

hdodov commented Nov 17, 2017

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 remove nomin/ 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:

http://localhost/mysite/nomin/myproject/

will serve files from:

http://localhost/mysite/myproject/

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:

  • at the end without a trailing slash
  • at the end and your project uses files up the directory tree beyond its folder such that the URL ends up at or before the non-existent nomin folder
  • at the beginning (the root), like this http://localhost/nomin/mysite/myproject/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment