Skip to content

Instantly share code, notes, and snippets.

@hansspiess
Created August 10, 2012 19:47
Show Gist options
  • Save hansspiess/3317319 to your computer and use it in GitHub Desktop.
Save hansspiess/3317319 to your computer and use it in GitHub Desktop.
.htaccess: Localhost / Live Server Switch
RewriteBase /
# Copy HTTP Authorization header value to HTTP_AUTOHRIZATION server variable for use by script
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# On live server, rewrite requests for URL-paths which do not resolve to specific
# physically-existing filetypes to my script, excluding the script's URL-path itself.
RewriteCond %{HTTP_HOST} !^localhost$
RewriteCond $1 !^index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (^[^.]*|\.(php|html?|feed|pdf|raw))$ index.php [NC,L]
# On localhost dev server, rewrite requests for URL-paths which do not resolve to specific
# physically-existing filetypes to my dev script, excluding the script's URL-path itself.
RewriteCond %{HTTP_HOST} ^localhost$
RewriteCond $1 !^localhost_path/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (^[^.]*|\.(php|html?|feed|pdf|raw))$ localhost_path/index.php [NC,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment