Created
November 16, 2014 13:21
-
-
Save chibani/722890b95cde1242ed67 to your computer and use it in GitHub Desktop.
.htaccess specific version
This file contains 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
# Use case (mine) : | |
# You're deploying a new version of a website on client's hosting. | |
# Of course, the previous website is in the root directory... | |
# You want your v2/ directory to be visible only for you and the client | |
# And the client (and perhaps you) doesn't have a static IP... | |
# | |
# In this case, I've decided to use a cookie. | |
# But, how may I set a cookie in the clients browser ? | |
# What if she wants to browser thi shinny new website with her smartphone or tablet ??? | |
# What if she wants to show it to her team or even family ??? | |
# | |
# Here's my solution to this problem : | |
# | |
# Usage : | |
# To set the cookie to use the /v2 directory, visit : www.mydomainname.com/__set/v2 | |
# To see back the original version, set a directory that doesn't exist : www.mydomainname/__set/whatever | |
# | |
# The code : | |
RewriteEngine on | |
#Setting a specific version | |
RewriteRule __set/(.+)$ / [L,R=302,CO=dversion:$1:%{HTTP_HOST}:1440] | |
#Using a specific version based on the cookie previously set | |
RewriteCond %{HTTP:Cookie} [^|;\s]*dversion=(v[^|;\s]*) | |
RewriteCond %{DOCUMENT_ROOT}%1 -d | |
RewriteCond %{REQUEST_URI} !^/%1.* | |
RewriteRule ^(.*)$ %1/$1 [L,QSA] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment